class Clamp::Parameter::Definition

Constants

ELLIPSIS_SUFFIX
OPTIONAL
VALID_ATTRIBUTE_NAME

Attributes

name[R]

Public Class Methods

new(name, description, options = {}) click to toggle source
Calls superclass method Clamp::Attribute::Definition.new
# File lib/clamp/parameter/definition.rb, line 8
def initialize(name, description, options = {})
  @name = name
  @description = description
  super(options)
  @multivalued = (@name =~ ELLIPSIS_SUFFIX)
  @required = options.fetch(:required) do
    (@name !~ OPTIONAL)
  end
  @inheritable = options.fetch(:inheritable, true)
end

Public Instance Methods

consume(arguments) click to toggle source
# File lib/clamp/parameter/definition.rb, line 29
def consume(arguments)
  raise ArgumentError, Clamp.message(:no_value_provided) if required? && arguments.empty?
  arguments.shift(multivalued? ? arguments.length : 1)
end
help_lhs() click to toggle source
# File lib/clamp/parameter/definition.rb, line 25
def help_lhs
  name
end
inheritable?() click to toggle source
# File lib/clamp/parameter/definition.rb, line 21
def inheritable?
  @inheritable
end

Private Instance Methods

infer_attribute_name() click to toggle source
# File lib/clamp/parameter/definition.rb, line 41
def infer_attribute_name
  inferred_name = name.downcase.tr("-", "_").sub(ELLIPSIS_SUFFIX, "").sub(OPTIONAL) { Regexp.last_match(1) }
  unless inferred_name =~ VALID_ATTRIBUTE_NAME
    raise "cannot infer attribute_name from #{name.inspect}"
  end
  inferred_name += "_list" if multivalued?
  inferred_name
end