Class: Clamp::Attribute::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/clamp/attribute/definition.rb

Direct Known Subclasses

Option::Definition, Parameter::Definition

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Definition

Returns a new instance of Definition.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/clamp/attribute/definition.rb', line 8

def initialize(options)
  if options.has_key?(:attribute_name)
    @attribute_name = options[:attribute_name].to_s
  end
  if options.has_key?(:default)
    @default_value = options[:default]
  end
  if options.has_key?(:environment_variable)
    @environment_variable = options[:environment_variable]
  end
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



20
21
22
# File 'lib/clamp/attribute/definition.rb', line 20

def description
  @description
end

#environment_variableObject (readonly)

Returns the value of attribute environment_variable.



20
21
22
# File 'lib/clamp/attribute/definition.rb', line 20

def environment_variable
  @environment_variable
end

Instance Method Details

#attribute_nameObject



58
59
60
# File 'lib/clamp/attribute/definition.rb', line 58

def attribute_name
  @attribute_name ||= infer_attribute_name
end

#default_methodObject



38
39
40
# File 'lib/clamp/attribute/definition.rb', line 38

def default_method
  "default_#{read_method}"
end

#default_valueObject



62
63
64
65
66
67
68
# File 'lib/clamp/attribute/definition.rb', line 62

def default_value
  if defined?(@default_value)
    @default_value
  elsif multivalued?
    []
  end
end

#helpObject



26
27
28
# File 'lib/clamp/attribute/definition.rb', line 26

def help
  [help_lhs, help_rhs]
end

#help_rhsObject



22
23
24
# File 'lib/clamp/attribute/definition.rb', line 22

def help_rhs
  description + default_description
end

#ivar_nameObject



30
31
32
# File 'lib/clamp/attribute/definition.rb', line 30

def ivar_name
  "@#{attribute_name}"
end

#multivalued?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/clamp/attribute/definition.rb', line 50

def multivalued?
  @multivalued
end

#of(command) ⇒ Object



70
71
72
# File 'lib/clamp/attribute/definition.rb', line 70

def of(command)
  Attribute::Instance.new(self, command)
end

#read_methodObject



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

def read_method
  attribute_name
end

#required?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/clamp/attribute/definition.rb', line 54

def required?
  @required
end

#write_methodObject



42
43
44
45
46
47
48
# File 'lib/clamp/attribute/definition.rb', line 42

def write_method
  if multivalued?
    "append_to_#{attribute_name}"
  else
    "#{attribute_name}="
  end
end