class Dry::Initializer::Definition

@private @abstract

Base class for parameter or option definitions Defines methods to add corresponding reader to the class, and build value of instance attribute.

Attributes

default[R]
desc[R]
ivar[R]
null[R]
option[R]
optional[R]
reader[R]
source[R]
target[R]
type[R]

Public Class Methods

new(**options) click to toggle source
# File lib/dry/initializer/definition.rb, line 55
def initialize(**options)
  @option   = options[:option]
  @null     = options[:null]
  @source   = options[:source]
  @target   = options[:target]
  @ivar     = "@#{@target}"
  @type     = options[:type]
  @reader   = options[:reader]
  @default  = options[:default]
  @optional = options[:optional]
  @desc     = options[:desc]
end

Public Instance Methods

==(other) click to toggle source
# File lib/dry/initializer/definition.rb, line 36
def ==(other)
  other.instance_of?(self.class) && (other.source == source)
end
code() click to toggle source
# File lib/dry/initializer/definition.rb, line 40
def code
  Builders::Reader[self]
end
inch() click to toggle source
# 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
inspect()
Alias for: name
name() click to toggle source
# File lib/dry/initializer/definition.rb, line 29
def name
  @name ||= "#{option ? "option" : "parameter"} '#{source}'"
end
Also aliased as: to_s, to_str, inspect
options() click to toggle source
# File lib/dry/initializer/definition.rb, line 18
def options
  {
    as: target,
    type: type,
    optional: optional,
    default: default,
    reader: reader,
    desc: desc
  }.compact
end
to_s()
Alias for: name
to_str()
Alias for: name