Class: Dry::Initializer::Definition Abstract
- Inherits:
-
Object
- Object
- Dry::Initializer::Definition
- Defined in:
- lib/dry/initializer/definition.rb
Overview
Base class for parameter or option definitions Defines methods to add corresponding reader to the class, and build value of instance attribute.
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#desc ⇒ Object
readonly
Returns the value of attribute desc.
-
#ivar ⇒ Object
readonly
Returns the value of attribute ivar.
-
#null ⇒ Object
readonly
Returns the value of attribute null.
-
#option ⇒ Object
readonly
Returns the value of attribute option.
-
#optional ⇒ Object
readonly
Returns the value of attribute optional.
-
#reader ⇒ Object
readonly
Returns the value of attribute reader.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #code ⇒ Object
- #inch ⇒ Object
- #name ⇒ Object (also: #to_s, #to_str, #inspect)
- #options ⇒ Object
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
11 12 13 |
# File 'lib/dry/initializer/definition.rb', line 11 def default @default end |
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
11 12 13 |
# File 'lib/dry/initializer/definition.rb', line 11 def desc @desc end |
#ivar ⇒ Object (readonly)
Returns the value of attribute ivar.
11 12 13 |
# File 'lib/dry/initializer/definition.rb', line 11 def ivar @ivar end |
#null ⇒ Object (readonly)
Returns the value of attribute null.
11 12 13 |
# File 'lib/dry/initializer/definition.rb', line 11 def null @null end |
#option ⇒ Object (readonly)
Returns the value of attribute option.
11 12 13 |
# File 'lib/dry/initializer/definition.rb', line 11 def option @option end |
#optional ⇒ Object (readonly)
Returns the value of attribute optional.
11 12 13 |
# File 'lib/dry/initializer/definition.rb', line 11 def optional @optional end |
#reader ⇒ Object (readonly)
Returns the value of attribute reader.
11 12 13 |
# File 'lib/dry/initializer/definition.rb', line 11 def reader @reader end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
11 12 13 |
# File 'lib/dry/initializer/definition.rb', line 11 def source @source end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
11 12 13 |
# File 'lib/dry/initializer/definition.rb', line 11 def target @target end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
11 12 13 |
# File 'lib/dry/initializer/definition.rb', line 11 def type @type end |
Instance Method Details
#==(other) ⇒ Object
33 34 35 |
# File 'lib/dry/initializer/definition.rb', line 33 def ==(other) other.instance_of?(self.class) && (other.source == source) end |
#code ⇒ Object
37 38 39 |
# File 'lib/dry/initializer/definition.rb', line 37 def code Builders::Reader[self] end |
#inch ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/dry/initializer/definition.rb', line 41 def inch @inch ||= (option ? '@option' : '@param ').tap do |text| text << ' [Object]' text << (option ? " :#{source}" : " #{source}") text << (optional ? ' (optional)' : ' (required)') text << " #{desc}" if desc end end |
#name ⇒ Object Also known as: to_s, to_str, inspect
26 27 28 |
# File 'lib/dry/initializer/definition.rb', line 26 def name @name ||= (option ? 'option' : 'parameter') << " '#{source}'" end |
#options ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dry/initializer/definition.rb', line 15 def { as: target, type: type, optional: optional, default: default, reader: reader, desc: desc }.reject { |_, value| value.nil? } end |