Module: Dry::Initializer::Mixin

Defined in:
lib/dry/initializer/mixin.rb

Overview

Class-level DSL for the initializer

Instance Method Summary collapse

Instance Method Details

#option(name, **options) ⇒ self

Declares a named argument

Parameters:

  • name (#to_sym)
  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :default (Object)

    The default value

  • :type (#call)

    The type constraings via ‘dry-types`

  • :reader (Boolean) — default: true

    Whether to define attr_reader

Returns:

  • (self)

    itself



25
26
27
28
# File 'lib/dry/initializer/mixin.rb', line 25

def option(name, **options)
  arguments_builder.define_initializer(name, option: true, **options)
  self
end

#param(name, **options) ⇒ self

Declares a plain argument

Parameters:

  • name (#to_sym)
  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :default (Object)

    The default value

  • :type (#call)

    The type constraings via ‘dry-types`

  • :reader (Boolean) — default: true

    Whether to define attr_reader

Returns:

  • (self)

    itself



14
15
16
17
# File 'lib/dry/initializer/mixin.rb', line 14

def param(name, **options)
  arguments_builder.define_initializer(name, option: false, **options)
  self
end