Class: RakeCommander::Option
Constant Summary
Base::ClassHelpers::NOT_USED
RakeCommander::Options::Name::DOUBLE_HYPHEN_REGEX, RakeCommander::Options::Name::HYPEN_REGEX, RakeCommander::Options::Name::HYPHEN_START_REGEX, RakeCommander::Options::Name::OPTIONAL_REGEX, RakeCommander::Options::Name::SINGLE_HYPHEN_REGEX, RakeCommander::Options::Name::SPACE_REGEX, RakeCommander::Options::Name::UNDERSCORE_REGEX
Instance Attribute Summary collapse
Instance Method Summary
collapse
class_resolver, descendants, descendants?, inheritable_attrs, inheritable_class_vars, inherited, instance_variable_name, new_class, redef_without_warning, resolve_class, to_constant, used_param?
argument_optional?, double_hyphen?, name_argument, name_argument?, name_hyphen?, name_sym, name_word_sym, short_hyphen?, short_sym, single_hyphen?, valid_name?, valid_short?
Constructor Details
#initialize(short, name, *args, **kargs) {|_self| ... } ⇒ Option
Returns a new instance of Option.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/rake-commander/option.rb', line 11
def initialize(short, name, *args, **kargs, &block)
raise ArgumentError, "A short of one letter should be provided. Given: #{short}" unless self.class.valid_short?(short)
raise ArgumentError, "A name should be provided. Given: #{name}" unless self.class.valid_name?(name)
@name_full = name
super(short, name)
@default = kargs[:default] if kargs.key?(:default)
@desc = kargs[:desc] if kargs.key?(:desc)
@required = kargs[:required] if kargs.key?(:required)
@other_args = args
@original_block = block
yield(self) if block_given?
configure_other
end
|
Instance Attribute Details
#default ⇒ Object
Returns the value of attribute default.
7
8
9
|
# File 'lib/rake-commander/option.rb', line 7
def default
@default
end
|
#desc ⇒ Object
Returns the value of attribute desc.
7
8
9
|
# File 'lib/rake-commander/option.rb', line 7
def desc
@desc
end
|
#name_full ⇒ Object
Returns the value of attribute name_full.
9
10
11
|
# File 'lib/rake-commander/option.rb', line 9
def name_full
@name_full
end
|
#required=(value) ⇒ Object
Sets the attribute required
8
9
10
|
# File 'lib/rake-commander/option.rb', line 8
def required=(value)
@required = value
end
|
#type_coertion ⇒ Class, NilClass
67
68
69
|
# File 'lib/rake-commander/option.rb', line 67
def type_coertion
@type_coertion || (default? && default.class)
end
|
Instance Method Details
#add_switch(opts_parser, where: :base, &middleware) ⇒ Object
Note:
it allows to add a middleware block that will be called at parse runtime
Adds this option's switch to the OptionParser
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/rake-commander/option.rb', line 78
def add_switch(opts_parser, where: :base, &middleware)
raise "Expecting OptionParser. Given: #{opts_parser.class}" unless opts_parser.is_a?(OptionParser)
case where
when :head, :top
opts_parser.on_head(*switch_args, &option_block(&middleware))
when :tail, :end
opts_parser.on_tail(*switch_args, &option_block(&middleware))
else opts_parser.on(*switch_args, &option_block(&middleware))
end
opts_parser
end
|
#argument ⇒ Object
56
57
58
59
|
# File 'lib/rake-commander/option.rb', line 56
def argument
return nil unless argument?
self.class.name_argument(name_full)
end
|
#argument? ⇒ Boolean
51
52
53
|
# File 'lib/rake-commander/option.rb', line 51
def argument?
self.class.name_argument?(name_full)
end
|
#argument_required? ⇒ Boolean
62
63
64
|
# File 'lib/rake-commander/option.rb', line 62
def argument_required?
self.class.argument_required?(argument)
end
|
#default? ⇒ Boolean
72
73
74
|
# File 'lib/rake-commander/option.rb', line 72
def default?
instance_variable_defined?(:@default)
end
|
#name ⇒ Symbol
41
42
43
|
# File 'lib/rake-commander/option.rb', line 41
def name
self.class.name_word_sym(super)
end
|
#name_hyphen ⇒ String
46
47
48
|
# File 'lib/rake-commander/option.rb', line 46
def name_hyphen
self.class.name_hyphen(name_full)
end
|
#required? ⇒ Boolean
26
27
28
|
# File 'lib/rake-commander/option.rb', line 26
def required?
!!@required
end
|
#short ⇒ Symbol
31
32
33
|
# File 'lib/rake-commander/option.rb', line 31
def short
self.class.short_sym(super)
end
|
#short_hyphen ⇒ String
36
37
38
|
# File 'lib/rake-commander/option.rb', line 36
def short_hyphen
self.class.short_hyphen(short)
end
|
#switch_args ⇒ Array<Variant>
92
93
94
95
96
97
98
99
100
|
# File 'lib/rake-commander/option.rb', line 92
def switch_args
configure_other
args = [short_hyphen, name_hyphen]
if str = switch_desc
args << str
end
args << type_coertion if type_coertion
args
end
|