Class: Dry::Initializer::Argument Private
- Inherits:
-
Object
- Object
- Dry::Initializer::Argument
- Includes:
- Errors
- Defined in:
- lib/dry/initializer/argument.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.
A simple structure describes an argument (either param, or option)
Constant Summary collapse
- UNDEFINED =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Object.new.freeze
Instance Attribute Summary collapse
-
#default ⇒ Boolean
readonly
private
Whether the argument has a default value.
-
#default_value ⇒ Object
readonly
private
The default value of the argument.
-
#name ⇒ Symbol
readonly
private
The name of the argument.
-
#option ⇒ Boolean
readonly
private
Whether this is an option, or param of the initializer.
-
#reader ⇒ Boolean
readonly
private
Whether an attribute reader is defined for the argument.
-
#type ⇒ Class?
readonly
private
A type constraint.
Instance Method Summary collapse
- #==(other) ⇒ Object private
- #assignment ⇒ Object private
- #default_assignment ⇒ Object private
-
#initialize(name, option:, reader: true, **options) ⇒ Argument
constructor
private
A new instance of Argument.
- #signature ⇒ Object private
- #type_constraint ⇒ Object private
Constructor Details
#initialize(name, option:, reader: true, **options) ⇒ Argument
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 Argument.
36 37 38 39 40 41 42 |
# File 'lib/dry/initializer/argument.rb', line 36 def initialize(name, option:, reader: true, **) @name = name.to_sym @option = option @reader = reader assign_default_value() assign_type() end |
Instance Attribute Details
#default ⇒ Boolean (readonly)
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 whether the argument has a default value.
22 23 24 |
# File 'lib/dry/initializer/argument.rb', line 22 def default @default end |
#default_value ⇒ Object (readonly)
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 the default value of the argument.
26 27 28 |
# File 'lib/dry/initializer/argument.rb', line 26 def default_value @default_value end |
#name ⇒ Symbol (readonly)
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 the name of the argument.
18 19 20 |
# File 'lib/dry/initializer/argument.rb', line 18 def name @name end |
#option ⇒ Boolean (readonly)
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 Whether this is an option, or param of the initializer.
14 15 16 |
# File 'lib/dry/initializer/argument.rb', line 14 def option @option end |
#reader ⇒ Boolean (readonly)
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 whether an attribute reader is defined for the argument.
34 35 36 |
# File 'lib/dry/initializer/argument.rb', line 34 def reader @reader end |
#type ⇒ Class? (readonly)
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 type constraint.
30 31 32 |
# File 'lib/dry/initializer/argument.rb', line 30 def type @type end |
Instance Method Details
#==(other) ⇒ 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.
44 45 46 |
# File 'lib/dry/initializer/argument.rb', line 44 def ==(other) other.name == name end |
#assignment ⇒ 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.
58 59 60 |
# File 'lib/dry/initializer/argument.rb', line 58 def assignment "@#{name} = #{name}" end |
#default_assignment ⇒ 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.
62 63 64 65 |
# File 'lib/dry/initializer/argument.rb', line 62 def default_assignment "@#{name} = instance_eval(&__arguments__[:#{name}].default_value)" \ " if #{name} == Dry::Initializer::Argument::UNDEFINED" end |
#signature ⇒ 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.
48 49 50 51 52 53 54 55 56 |
# File 'lib/dry/initializer/argument.rb', line 48 def signature case [option, default] when [false, false] then name when [false, true] then "#{name} = Dry::Initializer::Argument::UNDEFINED" when [true, false] then "#{name}:" else "#{name}: Dry::Initializer::Argument::UNDEFINED" end end |
#type_constraint ⇒ 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.
67 68 69 |
# File 'lib/dry/initializer/argument.rb', line 67 def type_constraint "__arguments__[:#{name}].type.call(@#{name})" end |