Module: Dry::Initializer

Defined in:
lib/dry/initializer.rb,
lib/dry/initializer/errors.rb,
lib/dry/initializer/builder.rb,
lib/dry/initializer/argument.rb,
lib/dry/initializer/arguments.rb

Overview

Declares arguments of the initializer (params and options)

Defined Under Namespace

Modules: Errors Classes: Argument, Arguments, Builder

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



34
35
36
37
# File 'lib/dry/initializer.rb', line 34

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



23
24
25
26
# File 'lib/dry/initializer.rb', line 23

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