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.



11
12
13
# File 'lib/dry/initializer/definition.rb', line 11

def default
  @default
end

#descObject (readonly)

Returns the value of attribute desc.



11
12
13
# File 'lib/dry/initializer/definition.rb', line 11

def desc
  @desc
end

#ivarObject (readonly)

Returns the value of attribute ivar.



11
12
13
# File 'lib/dry/initializer/definition.rb', line 11

def ivar
  @ivar
end

#nullObject (readonly)

Returns the value of attribute null.



11
12
13
# File 'lib/dry/initializer/definition.rb', line 11

def null
  @null
end

#optionObject (readonly)

Returns the value of attribute option.



11
12
13
# File 'lib/dry/initializer/definition.rb', line 11

def option
  @option
end

#optionalObject (readonly)

Returns the value of attribute optional.



11
12
13
# File 'lib/dry/initializer/definition.rb', line 11

def optional
  @optional
end

#readerObject (readonly)

Returns the value of attribute reader.



11
12
13
# File 'lib/dry/initializer/definition.rb', line 11

def reader
  @reader
end

#sourceObject (readonly)

Returns the value of attribute source.



11
12
13
# File 'lib/dry/initializer/definition.rb', line 11

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



11
12
13
# File 'lib/dry/initializer/definition.rb', line 11

def target
  @target
end

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

#codeObject



37
38
39
# File 'lib/dry/initializer/definition.rb', line 37

def code
  Builders::Reader[self]
end

#inchObject



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

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

#optionsObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/dry/initializer/definition.rb', line 15

def options
  {
    as: target,
    type: type,
    optional: optional,
    default: default,
    reader: reader,
    desc: desc
  }.reject { |_, value| value.nil? }
end