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

#append_methodObject



46
47
48
49
50
# File 'lib/clamp/attribute/definition.rb', line 46

def append_method
  if multivalued?
    "append_to_#{attribute_name}"
  end
end

#attribute_nameObject



60
61
62
# File 'lib/clamp/attribute/definition.rb', line 60

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



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

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)


52
53
54
# File 'lib/clamp/attribute/definition.rb', line 52

def multivalued?
  @multivalued
end

#of(command) ⇒ Object



72
73
74
# File 'lib/clamp/attribute/definition.rb', line 72

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)


56
57
58
# File 'lib/clamp/attribute/definition.rb', line 56

def required?
  @required
end

#write_methodObject



42
43
44
# File 'lib/clamp/attribute/definition.rb', line 42

def write_method
  "#{attribute_name}="
end