Module: Dry::Initializer::DSL

Included in:
Dry::Initializer, Mixin
Defined in:
lib/dry/initializer/dsl.rb

Overview

Module-level DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nullnil, Dry::Initializer::UNDEFINED (readonly)

Setting for null (undefined value)

Returns:



9
10
11
# File 'lib/dry/initializer/dsl.rb', line 9

def null
  @null
end

Instance Method Details

#[](undefined: true) ⇒ Dry::Initializer

Returns a version of the module with custom settings

Parameters:

  • settings (Hash)

    a customizable set of options

Returns:



15
16
17
18
19
20
21
22
# File 'lib/dry/initializer/dsl.rb', line 15

def [](undefined: true, **)
  null = undefined == false ? nil : UNDEFINED
  Module.new.tap do |mod|
    mod.extend DSL
    mod.include self
    mod.send(:instance_variable_set, :@null, null)
  end
end

#define(procedure = nil) { ... } ⇒ Module

Returns mixin module to be included to target class by hand

Yields:

  • proc defining params and options

Returns:

  • (Module)


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

def define(procedure = nil, &block)
  config = Config.new(null: null)
  config.instance_exec(&(procedure || block))
  config.mixin.include Mixin::Root
  config.mixin
end