Class: Dry::Initializer::Builder Private

Inherits:
Object
  • Object
show all
Includes:
Plugins
Defined in:
lib/dry/initializer/builder.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Rebuilds the initializer every time a new argument defined

Instance Method Summary collapse

Constructor Details

#initializeBuilder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Builder.



10
11
12
13
14
# File 'lib/dry/initializer/builder.rb', line 10

def initialize
  @signature = Signature.new
  @plugins   = Set.new [VariableSetter, TypeConstraint, DefaultProc]
  @parts     = []
end

Instance Method Details

#call(mixin) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Redeclares initializer and readers in the mixin module

Parameters:

  • mixin (Module)


65
66
67
68
69
70
# File 'lib/dry/initializer/builder.rb', line 65

def call(mixin)
  define_readers(mixin)
  reload_initializer(mixin)
  reload_callback(mixin)
  mixin
end

#define(name, settings) ⇒ Dry::Initializer::Builder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Defines new agrument and reloads mixin definitions

Parameters:

  • name (#to_sym)
  • settings (Hash<Symbol, Object>)

Returns:



51
52
53
54
55
56
57
58
59
# File 'lib/dry/initializer/builder.rb', line 51

def define(name, settings)
  signature = @signature.add(name, settings)
  parts     = @parts + @plugins.map { |p| p.call(name, settings) }.compact

  copy do
    @signature = signature
    @parts     = parts
  end
end

#intolerant_to_unknown_optionsDry::Initializer::Builder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Makes builder to provide options-intolerant initializer



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

def intolerant_to_unknown_options
  copy { @tolerant = nil }
end

#register(plugin) ⇒ Dry::Initializer::Builder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Register new plugin to be applied as a chunk of code, or a proc to be evaluated in the instance’s scope

Parameters:

  • (Dry::Initializer::Plugin)

Returns:



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

def register(plugin)
  plugins = @plugins + [plugin]
  copy { @plugins = plugins }
end

#tolerant_to_unknown_optionsDry::Initializer::Builder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Makes builder to provide options-tolerant initializer



32
33
34
# File 'lib/dry/initializer/builder.rb', line 32

def tolerant_to_unknown_options
  copy { @tolerant = "**" }
end