Class: CMDx::Inputs::ChildBuilder

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeChildBuilder

Returns a new instance of ChildBuilder.



126
127
128
# File 'lib/cmdx/inputs.rb', line 126

def initialize
  @children = []
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



124
125
126
# File 'lib/cmdx/inputs.rb', line 124

def children
  @children
end

Class Method Details

.build { ... } ⇒ Array<Input>

Returns frozen list of built children.

Yields:

Returns:

  • (Array<Input>)

    frozen list of built children



116
117
118
119
120
# File 'lib/cmdx/inputs.rb', line 116

def build(&)
  builder = new
  builder.instance_eval(&)
  builder.children.freeze
end

Instance Method Details

#inputs(*names, **options) { ... } ⇒ Array<Input> Also known as: input

Parameters:

Options Hash (**options):

  • :description (String) — default: also accepts `:desc`
  • :as (Symbol)

    overrides the accessor name

  • :prefix (Boolean, String)

    prefix for the accessor name

  • :suffix (Boolean, String)

    suffix for the accessor name

  • :source (Symbol, Proc, #call) — default: `:context`

    where to fetch from

  • :default (Object, Symbol, Proc, #call)
  • :transform (Symbol, Proc, #call)

    mutator applied after coercion

  • :if (Symbol, Proc, #call)
  • :unless (Symbol, Proc, #call)
  • :required (Boolean)
  • :coerce (Object)

    forwarded with declaration (see Coercions#extract)

  • :validate (Object)

    forwarded with declaration (see Validators#extract)

Yields:

  • nested child input DSL

Returns:



146
147
148
# File 'lib/cmdx/inputs.rb', line 146

def inputs(*names, **options, &)
  build(*names, **options, &)
end

#optional(*names, **options) { ... } ⇒ Array<Input>

Declares optional child inputs (equivalent to ‘inputs …, required: false`).

Parameters:

Options Hash (**options):

  • :description (String) — default: also accepts `:desc`
  • :as (Symbol)

    overrides the accessor name

  • :prefix (Boolean, String)

    prefix for the accessor name

  • :suffix (Boolean, String)

    suffix for the accessor name

  • :source (Symbol, Proc, #call) — default: `:context`

    where to fetch from

  • :default (Object, Symbol, Proc, #call)
  • :transform (Symbol, Proc, #call)

    mutator applied after coercion

  • :if (Symbol, Proc, #call)
  • :unless (Symbol, Proc, #call)
  • :coerce (Object)

    forwarded with declaration (see Coercions#extract)

  • :validate (Object)

    forwarded with declaration (see Validators#extract)

Yields:

  • nested child input DSL

Returns:



167
168
169
# File 'lib/cmdx/inputs.rb', line 167

def optional(*names, **options, &)
  build(*names, required: false, **options, &)
end

#required(*names, **options) { ... } ⇒ Array<Input>

Declares required child inputs (equivalent to ‘inputs …, required: true`).

Parameters:

Options Hash (**options):

  • :description (String) — default: also accepts `:desc`
  • :as (Symbol)

    overrides the accessor name

  • :prefix (Boolean, String)

    prefix for the accessor name

  • :suffix (Boolean, String)

    suffix for the accessor name

  • :source (Symbol, Proc, #call) — default: `:context`

    where to fetch from

  • :default (Object, Symbol, Proc, #call)
  • :transform (Symbol, Proc, #call)

    mutator applied after coercion

  • :if (Symbol, Proc, #call)
  • :unless (Symbol, Proc, #call)
  • :coerce (Object)

    forwarded with declaration (see Coercions#extract)

  • :validate (Object)

    forwarded with declaration (see Validators#extract)

Yields:

  • nested child input DSL

Returns:



187
188
189
# File 'lib/cmdx/inputs.rb', line 187

def required(*names, **options, &)
  build(*names, required: true, **options, &)
end