Class: Dry::Initializer::Definition Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/initializer/definition.rb

Overview

This class is abstract.

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

Instance Method Summary collapse

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.


14
15
16
# File 'lib/dry/initializer/definition.rb', line 14

def default
  @default
end

#descObject (readonly)

Returns the value of attribute desc.


14
15
16
# File 'lib/dry/initializer/definition.rb', line 14

def desc
  @desc
end

#ivarObject (readonly)

Returns the value of attribute ivar.


14
15
16
# File 'lib/dry/initializer/definition.rb', line 14

def ivar
  @ivar
end

#nullObject (readonly)

Returns the value of attribute null.


14
15
16
# File 'lib/dry/initializer/definition.rb', line 14

def null
  @null
end

#optionObject (readonly)

Returns the value of attribute option.


14
15
16
# File 'lib/dry/initializer/definition.rb', line 14

def option
  @option
end

#optionalObject (readonly)

Returns the value of attribute optional.


14
15
16
# File 'lib/dry/initializer/definition.rb', line 14

def optional
  @optional
end

#readerObject (readonly)

Returns the value of attribute reader.


14
15
16
# File 'lib/dry/initializer/definition.rb', line 14

def reader
  @reader
end

#sourceObject (readonly)

Returns the value of attribute source.


14
15
16
# File 'lib/dry/initializer/definition.rb', line 14

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.


14
15
16
# File 'lib/dry/initializer/definition.rb', line 14

def target
  @target
end

#typeObject (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

#codeObject


40
41
42
# File 'lib/dry/initializer/definition.rb', line 40

def code
  Builders::Reader[self]
end

#inchObject


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

#nameObject 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

#optionsObject


18
19
20
21
22
23
24
25
26
27
# File 'lib/dry/initializer/definition.rb', line 18

def options
  {
    as: target,
    type: type,
    optional: optional,
    default: default,
    reader: reader,
    desc: desc
  }.compact
end