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.
59 60 61 62 63 64 65 66 |
# File 'lib/cmdx/inputs.rb', line 59 def deregister(klass, *names) names.each do |name| input = registry.delete(name.to_sym) klass.send(:undefine_input_reader, input) end self end |
#empty? ⇒ Boolean
69 70 71 |
# File 'lib/cmdx/inputs.rb', line 69 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.
83 84 85 86 87 88 89 |
# File 'lib/cmdx/inputs.rb', line 83 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
74 75 76 |
# File 'lib/cmdx/inputs.rb', line 74 def size registry.size end |