Class: Clamp::Parameter::Definition

Inherits:
Attribute::Definition show all
Defined in:
lib/clamp/parameter/definition.rb

Overview

Represents an parameter of a Clamp::Command class.

Instance Attribute Summary collapse

Attributes inherited from Attribute::Definition

#description, #environment_variable

Instance Method Summary collapse

Methods inherited from Attribute::Definition

#append_method, #attribute_name, #default_method, #default_value, #help, #help_rhs, #hidden?, #ivar_name, #multivalued?, #of, #option_missing_message, #read_method, #required?, #write_method

Constructor Details

#initialize(name, description, options = {}) ⇒ Definition

Returns a new instance of Definition.



12
13
14
15
16
17
18
19
20
21
# File 'lib/clamp/parameter/definition.rb', line 12

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



23
24
25
# File 'lib/clamp/parameter/definition.rb', line 23

def name
  @name
end

Instance Method Details

#consume(arguments) ⇒ Object

Raises:

  • (ArgumentError)


33
34
35
36
# File 'lib/clamp/parameter/definition.rb', line 33

def consume(arguments)
  raise ArgumentError, Clamp.message(:no_value_provided) if required? && arguments.empty?
  arguments.shift(multivalued? ? arguments.length : 1)
end

#help_lhsObject



29
30
31
# File 'lib/clamp/parameter/definition.rb', line 29

def help_lhs
  name
end

#inheritable?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/clamp/parameter/definition.rb', line 25

def inheritable?
  @inheritable
end