Class: Tomo::CLI::Rules
- Inherits:
-
Object
show all
- Defined in:
- lib/tomo/cli/rules.rb,
lib/tomo/cli/rules/switch.rb,
lib/tomo/cli/rules/argument.rb,
lib/tomo/cli/rules/value_switch.rb
Defined Under Namespace
Classes: Argument, Switch, ValueSwitch
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Rules
Returns a new instance of Rules.
24
25
26
|
# File 'lib/tomo/cli/rules.rb', line 24
def initialize
@rules = []
end
|
Instance Method Details
#add_arg(spec, values_proc) ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/tomo/cli/rules.rb', line 28
def add_arg(spec, values_proc)
rule = ARG_PATTERNS.find do |regexp, method|
break send(method, spec, values_proc) if regexp.match?(spec)
end
raise ArgumentError, "Unrecognized arg style: #{spec}" if rule.nil?
rules << rule
end
|
#add_option(key, spec, values_proc, &block) ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/tomo/cli/rules.rb', line 37
def add_option(key, spec, values_proc, &block)
rule = OPTION_PATTERNS.find do |regexp, method|
match = regexp.match(spec)
break send(method, key, *match.captures, values_proc, block) if match
end
raise ArgumentError, "Unrecognized option style: #{spec}" if rule.nil?
rules << rule
end
|
#to_a ⇒ Object
47
48
49
|
# File 'lib/tomo/cli/rules.rb', line 47
def to_a
rules
end
|