Module: AceMQ::Rails::Registry

Defined in:
lib/acemq/rails/registry.rb

Overview

Every Consumer subclass that has been loaded.

Keyed by name rather than held as a set of classes, and that is the whole reason this is not a one-line array. Zeitwerk unloads a constant and loads a new class object under the same name on every reload; a set would grow a second OrdersConsumer every time somebody saved the file, and the consumer process would subscribe to the same queue four times after an afternoon's work. Keyed by name, a reload replaces.

An anonymous class — one made in a spec with Class.new(Consumer) — has no name to key on and is kept under its object id instead, so tests do not collide with each other and do not need to know this exists.

Class Method Summary collapse

Class Method Details

.classes ⇒ Array<Class>

Every registered class, in the order it was first registered.

Returns:

  • (Array<Class>)


47
48
49
# File 'lib/acemq/rails/registry.rb', line 47

def classes
  LOCK.synchronize { @classes.values.dup }
end

.clear ⇒ Object

Forgets everything. For specs, and for a reload that wants to start from nothing rather than trust the keying above.



63
64
65
66
# File 'lib/acemq/rails/registry.rb', line 63

def clear
  LOCK.synchronize { @classes = {} }
  nil
end

.queues ⇒ Array<String>

Returns every queue that will be subscribed.

Returns:

  • (Array<String>) —

    every queue that will be subscribed



59
# File 'lib/acemq/rails/registry.rb', line 59

def queues = runnable.map(&:queue)

.register(klass) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



39
40
41
42
# File 'lib/acemq/rails/registry.rb', line 39

def register(klass)
  LOCK.synchronize { @classes[key_for(klass)] = klass }
  klass
end

.runnable ⇒ Array<Class>

The ones the runner will actually subscribe: those with a queue.

Returns:

  • (Array<Class>)


54
55
56
# File 'lib/acemq/rails/registry.rb', line 54

def runnable
  classes.select { |klass| klass.respond_to?(:runnable?) && klass.runnable? }
end