Module: CobraCommander::Registry

Included in:
Source
Defined in:
lib/cobra_commander/registry.rb

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/cobra_commander/registry.rb', line 5

def [](key)
  Class.new(self) do
    define_singleton_method(:key) { key }
    define_method(:key) { key }

    def self.inherited(base)
      super
      superclass.all[key] = base
    end
  end
end

#allObject



17
18
19
# File 'lib/cobra_commander/registry.rb', line 17

def all
  @all ||= {}
end

#select(**selector) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/cobra_commander/registry.rb', line 21

def select(**selector)
  return all.values unless selector.values.any?

  all.filter_map do |key, klass|
    klass if selector[key]
  end
end