Class: CMDx::Inputs::ChildBuilder
- Inherits:
-
Object
- Object
- CMDx::Inputs::ChildBuilder
- Defined in:
- lib/cmdx/inputs.rb
Overview
DSL receiver for the block passed to #register. Builds a frozen list of child CMDx::Inputs. Supports arbitrary nesting: every DSL method accepts its own block.
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
Class Method Summary collapse
-
.build { ... } ⇒ Array<Input>
Frozen list of built children.
Instance Method Summary collapse
-
#initialize ⇒ ChildBuilder
constructor
A new instance of ChildBuilder.
- #inputs(*names, **options) { ... } ⇒ Array<Input> (also: #input)
-
#optional(*names, **options) { ... } ⇒ Array<Input>
Declares optional child inputs (equivalent to ‘inputs …, required: false`).
-
#required(*names, **options) { ... } ⇒ Array<Input>
Declares required child inputs (equivalent to ‘inputs …, required: true`).
Constructor Details
#initialize ⇒ ChildBuilder
Returns a new instance of ChildBuilder.
125 126 127 |
# File 'lib/cmdx/inputs.rb', line 125 def initialize @children = [] end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
123 124 125 |
# File 'lib/cmdx/inputs.rb', line 123 def children @children end |
Class Method Details
.build { ... } ⇒ Array<Input>
Returns frozen list of built children.
115 116 117 118 119 |
# File 'lib/cmdx/inputs.rb', line 115 def build(&) builder = new builder.instance_eval(&) builder.children.freeze end |
Instance Method Details
#inputs(*names, **options) { ... } ⇒ Array<Input> Also known as: input
145 146 147 |
# File 'lib/cmdx/inputs.rb', line 145 def inputs(*names, **, &) build(*names, **, &) end |
#optional(*names, **options) { ... } ⇒ Array<Input>
Declares optional child inputs (equivalent to ‘inputs …, required: false`). An explicit `required:` in `options` is ignored — use #inputs when you need to set the flag dynamically.
169 170 171 |
# File 'lib/cmdx/inputs.rb', line 169 def optional(*names, **, &) build(*names, **, required: false, &) end |
#required(*names, **options) { ... } ⇒ Array<Input>
Declares required child inputs (equivalent to ‘inputs …, required: true`). An explicit `required:` in `options` is ignored — use #inputs when you need to set the flag dynamically.
192 193 194 |
# File 'lib/cmdx/inputs.rb', line 192 def required(*names, **, &) build(*names, **, required: true, &) end |