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.
14 15 16 |
# File 'lib/dry/initializer/definition.rb', line 14 def default @default end |
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
14 15 16 |
# File 'lib/dry/initializer/definition.rb', line 14 def desc @desc end |
#ivar ⇒ Object (readonly)
Returns the value of attribute ivar.
14 15 16 |
# File 'lib/dry/initializer/definition.rb', line 14 def ivar @ivar end |
#null ⇒ Object (readonly)
Returns the value of attribute null.
14 15 16 |
# File 'lib/dry/initializer/definition.rb', line 14 def null @null end |
#option ⇒ Object (readonly)
Returns the value of attribute option.
14 15 16 |
# File 'lib/dry/initializer/definition.rb', line 14 def option @option end |
#optional ⇒ Object (readonly)
Returns the value of attribute optional.
14 15 16 |
# File 'lib/dry/initializer/definition.rb', line 14 def optional @optional end |
#reader ⇒ Object (readonly)
Returns the value of attribute reader.
14 15 16 |
# File 'lib/dry/initializer/definition.rb', line 14 def reader @reader end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
14 15 16 |
# File 'lib/dry/initializer/definition.rb', line 14 def source @source end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
14 15 16 |
# File 'lib/dry/initializer/definition.rb', line 14 def target @target end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
14 15 16 |
# File 'lib/dry/initializer/definition.rb', line 14 def type @type end |
Instance Method Details
#==(other) ⇒ Object
36 37 38 |
# File 'lib/dry/initializer/definition.rb', line 36 def ==(other) other.instance_of?(self.class) && (other.source == source) end |
#code ⇒ Object
40 41 42 |
# File 'lib/dry/initializer/definition.rb', line 40 def code Builders::Reader[self] end |
#inch ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/dry/initializer/definition.rb', line 44 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
29 30 31 |
# File 'lib/dry/initializer/definition.rb', line 29 def name @name ||= "#{option ? "option" : "parameter"} '#{source}'" end |
#options ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dry/initializer/definition.rb', line 18 def { as: target, type: type, optional: optional, default: default, reader: reader, desc: desc }.compact end |