Class: Synapse::Wiring::WireRegistry
- Inherits:
-
Object
- Object
- Synapse::Wiring::WireRegistry
- Defined in:
- lib/synapse/wiring/wire_registry.rb
Instance Method Summary collapse
-
#each_type {|Class| ... } ⇒ undefined
Yields the type that each wire is registered for.
- #initialize(duplicates_allowed) ⇒ undefined constructor
- #register(wire) ⇒ undefined
-
#wire_for(target_type) ⇒ Wire
Retrieves the most specific wire for a given type, if any.
-
#wires_for(target_type) ⇒ Array
Retrieves any wires for a given type, regardless of specificity.
Constructor Details
#initialize(duplicates_allowed) ⇒ undefined
6 7 8 9 |
# File 'lib/synapse/wiring/wire_registry.rb', line 6 def initialize(duplicates_allowed) @duplicates_allowed = duplicates_allowed @wires = Array.new end |
Instance Method Details
#each_type {|Class| ... } ⇒ undefined
Yields the type that each wire is registered for
15 16 17 18 19 |
# File 'lib/synapse/wiring/wire_registry.rb', line 15 def each_type @wires.each do |wire| yield wire.type end end |
#register(wire) ⇒ undefined
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/synapse/wiring/wire_registry.rb', line 25 def register(wire) unless @duplicates_allowed if @wires.include? wire raise DuplicateWireError end end @wires.push wire @wires.sort! end |
#wire_for(target_type) ⇒ Wire
Retrieves the most specific wire for a given type, if any
40 41 42 43 44 |
# File 'lib/synapse/wiring/wire_registry.rb', line 40 def wire_for(target_type) @wires.find do |wire| wire.type >= target_type end end |
#wires_for(target_type) ⇒ Array
Retrieves any wires for a given type, regardless of specificity
50 51 52 53 54 |
# File 'lib/synapse/wiring/wire_registry.rb', line 50 def wires_for(target_type) @wires.find_all do |wire| wire.type >= target_type end end |