Class: Clamp::Attribute::Definition
- Inherits:
-
Object
- Object
- Clamp::Attribute::Definition
show all
- Defined in:
- lib/clamp/attribute/definition.rb
Overview
Represents an attribute of a Clamp::Command class.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options) ⇒ Definition
Returns a new instance of Definition.
12
13
14
15
16
17
|
# File 'lib/clamp/attribute/definition.rb', line 12
def initialize(options)
@attribute_name = options[:attribute_name].to_s if options.key?(:attribute_name)
@default_value = options[:default] if options.key?(:default)
@environment_variable = options[:environment_variable] if options.key?(:environment_variable)
@hidden = options[:hidden] if options.key?(:hidden)
end
|
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
19
20
21
|
# File 'lib/clamp/attribute/definition.rb', line 19
def description
@description
end
|
#environment_variable ⇒ Object
Returns the value of attribute environment_variable.
19
20
21
|
# File 'lib/clamp/attribute/definition.rb', line 19
def environment_variable
@environment_variable
end
|
Instance Method Details
#append_method ⇒ Object
48
49
50
|
# File 'lib/clamp/attribute/definition.rb', line 48
def append_method
"append_to_#{attribute_name}" if multivalued?
end
|
#attribute_name ⇒ Object
64
65
66
|
# File 'lib/clamp/attribute/definition.rb', line 64
def attribute_name
@attribute_name ||= infer_attribute_name
end
|
#default_method ⇒ Object
40
41
42
|
# File 'lib/clamp/attribute/definition.rb', line 40
def default_method
"default_#{read_method}"
end
|
#default_value ⇒ Object
68
69
70
71
72
73
74
|
# File 'lib/clamp/attribute/definition.rb', line 68
def default_value
if defined?(@default_value)
@default_value
elsif multivalued?
[]
end
end
|
#help ⇒ Object
28
29
30
|
# File 'lib/clamp/attribute/definition.rb', line 28
def help
[help_lhs, help_rhs]
end
|
#help_rhs ⇒ Object
21
22
23
24
25
26
|
# File 'lib/clamp/attribute/definition.rb', line 21
def help_rhs
rhs = description
= required_indicator || default_description
rhs += " (#{})" if
rhs
end
|
#hidden? ⇒ Boolean
60
61
62
|
# File 'lib/clamp/attribute/definition.rb', line 60
def hidden?
@hidden ||= false
end
|
#ivar_name ⇒ Object
32
33
34
|
# File 'lib/clamp/attribute/definition.rb', line 32
def ivar_name
"@#{attribute_name}"
end
|
#multivalued? ⇒ Boolean
52
53
54
|
# File 'lib/clamp/attribute/definition.rb', line 52
def multivalued?
@multivalued
end
|
#of(command) ⇒ Object
76
77
78
|
# File 'lib/clamp/attribute/definition.rb', line 76
def of(command)
Attribute::Instance.new(self, command)
end
|
#option_missing_message ⇒ Object
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/clamp/attribute/definition.rb', line 80
def option_missing_message
if environment_variable
Clamp.message(:option_or_env_required,
option: switches.first,
env: environment_variable)
else
Clamp.message(:option_required,
option: switches.first)
end
end
|
#read_method ⇒ Object
36
37
38
|
# File 'lib/clamp/attribute/definition.rb', line 36
def read_method
attribute_name
end
|
#required? ⇒ Boolean
56
57
58
|
# File 'lib/clamp/attribute/definition.rb', line 56
def required?
@required ||= false
end
|
#write_method ⇒ Object
44
45
46
|
# File 'lib/clamp/attribute/definition.rb', line 44
def write_method
"#{attribute_name}="
end
|