Class: Brigadier::Parameters::Option
- Inherits:
-
Object
- Object
- Brigadier::Parameters::Option
show all
- Includes:
- Base
- Defined in:
- lib/brigadier/parameters/option.rb
Instance Attribute Summary
Attributes included from Base
#description, #name, #value
Instance Method Summary
collapse
Methods included from Base
#attribute_name, #block_defined?, #forbidden_parameters, #hidden?, #normalised_attribute_name, #required?, #valid?, #value?
Constructor Details
#initialize(name, description, args, block) ⇒ Option
6
7
8
9
10
11
12
13
|
# File 'lib/brigadier/parameters/option.rb', line 6
def initialize(name, description, args, block)
@name = name
@description = description
@args = args
@value = default_value
@block = block
assign_value_from_env_variable
end
|
Instance Method Details
#display_description ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/brigadier/parameters/option.rb', line 21
def display_description
opts = []
opts << 'default: %s' % [ default_value ] if default_value
opts << 'required: %s' % [ required? ]
opts << 'current: %s' % [ value.inspect ]
'%s (%s)' % [ description, opts.join(', ') ]
end
|
#display_name ⇒ Object
15
16
17
18
19
|
# File 'lib/brigadier/parameters/option.rb', line 15
def display_name
str = [ "--#{name}" ]
str << (required? ? '<value>' : '[<value>]')
str.join(' ')
end
|
#validate! ⇒ Object
29
30
31
32
|
# File 'lib/brigadier/parameters/option.rb', line 29
def validate!
validate_presence! if required?
validate_using_klass! if validator_klasses
end
|