Class: Dry::Initializer::Builder Private

Inherits:
Object
  • Object
show all
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.

Carries declarations for arguments along with a mixin module

Instance Method Summary collapse

Instance Method Details

#argumentsObject

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.



7
8
9
# File 'lib/dry/initializer/builder.rb', line 7

def arguments
  @arguments ||= Arguments.new
end

#define_attributes_reader(name, keys) ⇒ 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.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dry/initializer/builder.rb', line 20

def define_attributes_reader(name, keys)
  symbol_keys = keys.map { |key| ":" << key.to_s }.join(", ")
  key = '@#{key}'

  mixin.class_eval <<-RUBY
    def #{name}
      [#{symbol_keys}].inject({}) do |hash, key|
        hash.merge key => instance_variable_get(:"#{key}")
      end
    end
  RUBY
end

#define_initializer(name, **options) ⇒ 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.



15
16
17
18
# File 'lib/dry/initializer/builder.rb', line 15

def define_initializer(name, **options)
  @arguments = arguments.add(name, **options)
  mixin.instance_eval @arguments.declaration
end

#mixinObject

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.



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

def mixin
  @mixin ||= Module.new
end