Class: Railsmith::BaseService::InputRegistry
- Inherits:
-
Object
- Object
- Railsmith::BaseService::InputRegistry
- Defined in:
- lib/railsmith/base_service/input_registry.rb
Overview
Holds all InputDefinition objects declared on a service class. Supports inheritance via #dup — subclasses get their own copy that can be extended without affecting the parent.
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#all ⇒ Object
All registered definitions in declaration order.
- #any? ⇒ Boolean
-
#dup ⇒ Object
Returns a new InputRegistry with shallow copies of all definitions.
- #empty? ⇒ Boolean
-
#initialize ⇒ InputRegistry
constructor
A new instance of InputRegistry.
-
#register(definition) ⇒ Object
Register an InputDefinition.
Constructor Details
#initialize ⇒ InputRegistry
Returns a new instance of InputRegistry.
9 10 11 |
# File 'lib/railsmith/base_service/input_registry.rb', line 9 def initialize @definitions = {} end |
Instance Method Details
#[](name) ⇒ Object
25 26 27 |
# File 'lib/railsmith/base_service/input_registry.rb', line 25 def [](name) @definitions[name.to_sym] end |
#all ⇒ Object
All registered definitions in declaration order.
21 22 23 |
# File 'lib/railsmith/base_service/input_registry.rb', line 21 def all @definitions.values end |
#any? ⇒ Boolean
29 30 31 |
# File 'lib/railsmith/base_service/input_registry.rb', line 29 def any? @definitions.any? end |
#dup ⇒ Object
Returns a new InputRegistry with shallow copies of all definitions. InputDefinition objects are frozen so sharing them across classes is safe.
39 40 41 42 43 |
# File 'lib/railsmith/base_service/input_registry.rb', line 39 def dup copy = self.class.new @definitions.each_value { |d| copy.register(d) } copy end |
#empty? ⇒ Boolean
33 34 35 |
# File 'lib/railsmith/base_service/input_registry.rb', line 33 def empty? @definitions.empty? end |
#register(definition) ⇒ Object
Register an InputDefinition. Later registrations with the same name overwrite earlier ones (allows subclass override).
15 16 17 18 |
# File 'lib/railsmith/base_service/input_registry.rb', line 15 def register(definition) @definitions[definition.name] = definition self end |