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/struct.rb,
lib/dry/initializer/version.rb,
lib/dry/initializer/builders.rb,
lib/dry/initializer/undefined.rb,
lib/dry/initializer/definition.rb,
lib/dry/initializer/mixin/root.rb,
lib/dry/initializer/dispatchers.rb,
lib/dry/initializer/mixin/local.rb,
lib/dry/initializer/builders/reader.rb,
lib/dry/initializer/builders/attribute.rb,
lib/dry/initializer/builders/signature.rb,
lib/dry/initializer/builders/initializer.rb,
lib/dry/initializer/dispatchers/wrap_type.rb,
lib/dry/initializer/dispatchers/check_type.rb,
lib/dry/initializer/dispatchers/unwrap_type.rb,
lib/dry/initializer/dispatchers/prepare_ivar.rb,
lib/dry/initializer/dispatchers/prepare_reader.rb,
lib/dry/initializer/dispatchers/prepare_source.rb,
lib/dry/initializer/dispatchers/prepare_target.rb,
lib/dry/initializer/dispatchers/prepare_default.rb,
lib/dry/initializer/dispatchers/prepare_optional.rb,
lib/dry/initializer/dispatchers/build_nested_type.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.1.1"

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)

Yields:

  • block with nested definition

Returns:

  • (self)

    itself



47
48
49
50
# File 'lib/dry/initializer.rb', line 47

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



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

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