Class: Julewire::Core::Destinations::Registry
- Inherits:
-
Object
- Object
- Julewire::Core::Destinations::Registry
- Defined in:
- lib/julewire/core/destinations/registry.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add(destination) ⇒ Object
- #build(defaults:) ⇒ Object
- #clear ⇒ Object
- #copy ⇒ Object
- #empty? ⇒ Boolean
- #freeze ⇒ Object
-
#initialize(definitions = []) ⇒ Registry
constructor
A new instance of Registry.
- #use(name) ⇒ Object
Constructor Details
#initialize(definitions = []) ⇒ Registry
Returns a new instance of Registry.
22 23 24 |
# File 'lib/julewire/core/destinations/registry.rb', line 22 def initialize(definitions = []) @definitions = definitions.map { copy_definition(it) } end |
Class Method Details
.validate!(destination) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/julewire/core/destinations/registry.rb', line 11 def validate!(destination) DESTINATION_METHODS.each do |method_name| unless destination.respond_to?(method_name) raise ArgumentError, "destination must respond to ##{method_name}" end end destination end |
Instance Method Details
#add(destination) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/julewire/core/destinations/registry.rb', line 34 def add(destination) self.class.validate!(destination) raise ArgumentError, "destination #{destination.name.inspect} is already configured" if key?(destination.name) @definitions << destination self end |
#build(defaults:) ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/julewire/core/destinations/registry.rb', line 49 def build(defaults:) output_identities = {}.compare_by_identity @definitions.map do |definition| if definition.is_a?(Definition) definition.build(defaults: defaults, output_identities: output_identities) else definition end end.freeze end |
#clear ⇒ Object
42 43 44 45 |
# File 'lib/julewire/core/destinations/registry.rb', line 42 def clear @definitions.clear self end |
#copy ⇒ Object
60 61 62 |
# File 'lib/julewire/core/destinations/registry.rb', line 60 def copy self.class.new(@definitions) end |
#empty? ⇒ Boolean
47 |
# File 'lib/julewire/core/destinations/registry.rb', line 47 def empty? = @definitions.empty? |
#freeze ⇒ Object
64 65 66 67 |
# File 'lib/julewire/core/destinations/registry.rb', line 64 def freeze @definitions.freeze super end |
#use(name) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/julewire/core/destinations/registry.rb', line 26 def use(name, **) definition = Definition.new(name, **) raise ArgumentError, "destination #{definition.name.inspect} is already configured" if key?(definition.name) @definitions << definition self end |