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, type = nil, **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



27
28
29
30
31
32
# File 'lib/dry/initializer/mixin.rb', line 27

def option(name, type = nil, **options)
  options[:type]   = type if type
  options[:option] = true
  @initializer_builder = initializer_builder.define(name, **options)
  initializer_builder.call(self)
end

#param(name, type = nil, **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
18
19
# File 'lib/dry/initializer/mixin.rb', line 14

def param(name, type = nil, **options)
  options[:type]   = type if type
  options[:option] = false
  @initializer_builder = initializer_builder.define(name, **options)
  initializer_builder.call(self)
end

#register_initializer_plugin(plugin) ⇒ self

Adds new plugin to the builder

Parameters:

Returns:

  • (self)

    itself



39
40
41
42
# File 'lib/dry/initializer/mixin.rb', line 39

def register_initializer_plugin(plugin)
  @initializer_builder = initializer_builder.register(plugin)
  initializer_builder.call(self)
end