Class: AutoResp::RuleManager
- Inherits:
-
Object
- Object
- AutoResp::RuleManager
- Includes:
- RuleDSL
- Defined in:
- lib/ar/rule_manager.rb
Instance Method Summary collapse
- #add_handler(handler) ⇒ Object
- #add_rule(*args, &block) ⇒ Object
- #clear ⇒ Object
-
#initialize ⇒ RuleManager
constructor
A new instance of RuleManager.
- #rules ⇒ Object
Methods included from RuleDSL
Constructor Details
#initialize ⇒ RuleManager
Returns a new instance of RuleManager.
9 10 |
# File 'lib/ar/rule_manager.rb', line 9 def initialize end |
Instance Method Details
#add_handler(handler) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/ar/rule_manager.rb', line 20 def add_handler( handler ) if @last_rule rules[@last_rule] ||= [] rules[@last_rule] << handler end end |
#add_rule(*args, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ar/rule_manager.rb', line 27 def add_rule(*args, &block) @last_rule = target = args.first case target when Hash @last_rule = target.keys.first rules.merge! target when String, Regexp rules[target] = args[1] end rules[target] ||= block if block end |
#clear ⇒ Object
16 17 18 |
# File 'lib/ar/rule_manager.rb', line 16 def clear @rules.clear end |
#rules ⇒ Object
12 13 14 |
# File 'lib/ar/rule_manager.rb', line 12 def rules @rules ||= {} end |