Class: CMDx::Inputs
- Inherits:
-
Object
- Object
- CMDx::Inputs
- Defined in:
- lib/cmdx/inputs.rb
Overview
Defined Under Namespace
Classes: ChildBuilder
Instance Attribute Summary collapse
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
-
#deregister(klass, *names) ⇒ Inputs
Removes inputs and their accessor readers from
klass. - #empty? ⇒ Boolean
-
#initialize ⇒ Inputs
constructor
A new instance of Inputs.
- #initialize_copy(source) ⇒ void
-
#register(klass, *names, **options, &block) { ... } ⇒ Inputs
Declares one or more inputs and defines accessor readers on
klass. -
#resolve(task) ⇒ void
Resolves every input (with children) for
task, setting each input's computed value into its backing ivar so the generated readers return it. - #size ⇒ Integer
Constructor Details
#initialize ⇒ Inputs
Returns a new instance of Inputs.
11 12 13 |
# File 'lib/cmdx/inputs.rb', line 11 def initialize @registry = {} end |
Instance Attribute Details
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
9 10 11 |
# File 'lib/cmdx/inputs.rb', line 9 def registry @registry end |
Instance Method Details
#deregister(klass, *names) ⇒ Inputs
Removes inputs and their accessor readers from klass. Unknown names
are silently ignored (matching Outputs#deregister semantics).
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/cmdx/inputs.rb', line 60 def deregister(klass, *names) names.each do |name| input = registry.delete(name) next if input.nil? klass.send(:undefine_input_reader, input) end self end |
#empty? ⇒ Boolean
72 73 74 |
# File 'lib/cmdx/inputs.rb', line 72 def empty? registry.empty? end |
#initialize_copy(source) ⇒ void
This method returns an undefined value.
17 18 19 |
# File 'lib/cmdx/inputs.rb', line 17 def initialize_copy(source) @registry = source.registry.dup end |
#register(klass, *names, **options, &block) { ... } ⇒ Inputs
Declares one or more inputs and defines accessor readers on klass.
A block nests child inputs under each declared name (see ChildBuilder).
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cmdx/inputs.rb', line 42 def register(klass, *names, **, &block) children = block ? ChildBuilder.build(&block) : EMPTY_ARRAY names.each do |name| input = Input.new(name, children:, **) registry[input.name] = input klass.send(:define_input_reader, input) end self end |
#resolve(task) ⇒ void
This method returns an undefined value.
Resolves every input (with children) for task, setting each input's
computed value into its backing ivar so the generated readers return it.
86 87 88 89 90 91 92 |
# File 'lib/cmdx/inputs.rb', line 86 def resolve(task) registry.each_value do |input| value = input.resolve(task) task.instance_variable_set(input.ivar_name, value) resolve_children(input, value, task) end end |
#size ⇒ Integer
77 78 79 |
# File 'lib/cmdx/inputs.rb', line 77 def size registry.size end |