Module: Dry::Initializer

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

Overview

DSL for declaring params and options of class initializers

Defined Under Namespace

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

Constant Summary collapse

VERSION =
'3.0.3'.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



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

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)

Yields:

  • block with nested definition

Returns:

  • (self)

    itself



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

def option(name, type = nil, **opts, &block)
  dry_initializer.option(name, type, **opts, &block)
  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)

Yields:

  • block with nested definition

Returns:

  • (self)

    itself



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

def param(name, type = nil, **opts, &block)
  dry_initializer.param(name, type, **opts, &block)
  self
end