Class: Dry::Initializer::Arguments Private

Inherits:
Object
  • Object
show all
Includes:
Errors, Enumerable
Defined in:
lib/dry/initializer/arguments.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.

Collection of definitions for arguments

Instance Method Summary collapse

Constructor Details

#initialize(**arguments) ⇒ Arguments

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 Arguments.



10
11
12
# File 'lib/dry/initializer/arguments.rb', line 10

def initialize(**arguments)
  @arguments = arguments
end

Instance Method Details

#[](name) ⇒ 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.



34
35
36
# File 'lib/dry/initializer/arguments.rb', line 34

def [](name)
  @arguments[name]
end

#add(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.



14
15
16
17
18
19
20
# File 'lib/dry/initializer/arguments.rb', line 14

def add(name, options)
  validate_uniqueness(name)
  validate_presence_of_default(name, options)

  new_argument = Argument.new(name, options)
  self.class.new @arguments.merge(name.to_sym => new_argument)
end

#declarationObject

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.



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

def declaration
  <<-RUBY
    attr_reader #{select(&:reader).map { |arg| ":#{arg.name}" }.join(", ")}
    define_method :initialize do |#{signature}|
      #{assign_arguments}
      #{take_declarations}
      #{assign_defaults}
      #{check_constraints}
    end
  RUBY
end