Module: Dry::Initializer

Extended by:
DSL
Included in:
Mixin
Defined in:
lib/dry/initializer.rb,
lib/dry/initializer/dsl.rb,
lib/dry/initializer/mixin.rb,
lib/dry/initializer/config.rb,
lib/dry/initializer/builders.rb,
lib/dry/initializer/definition.rb,
lib/dry/initializer/dispatchers.rb

Overview

DSL for declaring params and options of class initializers

Defined Under Namespace

Modules: Builders, DSL, Dispatchers, Mixin Classes: Config, Definition

Constant Summary collapse

UNDEFINED =

Singleton for unassigned values

Object.new.freeze

Instance Attribute Summary

Attributes included from DSL

#null

Instance Method Summary collapse

Methods included from DSL

[], define

Instance Method Details

#dry_initializerDry::Initializer::Config

Gem-related configuration



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

def dry_initializer
  @dry_initializer ||= Config.new(self)
end

#option(name, type = nil, **opts) ⇒ self

Adds or redefines an option of [#dry_initializer]

Parameters:

  • name (Symbol)
  • type (#call, nil) (defaults to: nil)

    (nil)

  • opts (Hash)

    a customizable set of options

Options Hash (**opts):

  • :default (Proc)
  • :optional (Boolean)
  • :as (Symbol)
  • :reader (true, false, :protected, :public, :private)

Returns:

  • (self)

    itself



45
46
47
48
# File 'lib/dry/initializer.rb', line 45

def option(name, type = nil, **opts)
  dry_initializer.option(name, type, Dispatchers[opts])
  self
end

#param(name, type = nil, **opts) ⇒ self

Adds or redefines a parameter of [#dry_initializer]

Parameters:

  • name (Symbol)
  • type (#call, nil) (defaults to: nil)

    (nil)

  • opts (Hash)

    a customizable set of options

Options Hash (**opts):

  • :default (Proc)
  • :optional (Boolean)
  • :as (Symbol)
  • :reader (true, false, :protected, :public, :private)

Returns:

  • (self)

    itself



36
37
38
39
# File 'lib/dry/initializer.rb', line 36

def param(name, type = nil, **opts)
  dry_initializer.param(name, type, Dispatchers[opts])
  self
end