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
19
20
21
# 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
  if options.has_key?(:hidden)
    @hidden = options[:hidden]
  end
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

#environment_variableObject (readonly)

Returns the value of attribute environment_variable.



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

def environment_variable
  @environment_variable
end

Instance Method Details

#append_methodObject



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

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

#attribute_nameObject



67
68
69
# File 'lib/clamp/attribute/definition.rb', line 67

def attribute_name
  @attribute_name ||= infer_attribute_name
end

#default_methodObject



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

def default_method
  "default_#{read_method}"
end

#default_valueObject



71
72
73
74
75
76
77
# File 'lib/clamp/attribute/definition.rb', line 71

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

#helpObject



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

def help
  [help_lhs, help_rhs]
end

#help_rhsObject



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

def help_rhs
  description + default_description
end

#hidden?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/clamp/attribute/definition.rb', line 63

def hidden?
  @hidden
end

#ivar_nameObject



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

def ivar_name
  "@#{attribute_name}"
end

#multivalued?Boolean

Returns:

  • (Boolean)


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

def multivalued?
  @multivalued
end

#of(command) ⇒ Object



79
80
81
# File 'lib/clamp/attribute/definition.rb', line 79

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

#read_methodObject



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

def read_method
  attribute_name
end

#required?Boolean

Returns:

  • (Boolean)


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

def required?
  @required
end

#write_methodObject



45
46
47
# File 'lib/clamp/attribute/definition.rb', line 45

def write_method
  "#{attribute_name}="
end