Class: Sawtooth::Rules::DelegateRule
- Defined in:
- lib/sawtooth/rules/delegate_rule.rb
Overview
Can delegate to another set of rules, can be used to map the same rules to multiple tags.
Delegates must be mapped using ‘path/**`
Defined Under Namespace
Classes: CallbacksRule
Instance Attribute Summary collapse
-
#path ⇒ Object
Access the set of rules and prefix.
-
#prefix ⇒ Object
Access the set of rules and prefix.
-
#rules ⇒ Object
Access the set of rules and prefix.
Instance Method Summary collapse
-
#before_after_callbacks_rule ⇒ Object
Builds a special rule which invokes :before and :after callbacks on the supplied set of rules.
- #finish(path, doc, node) ⇒ Object
-
#initialize(options = {}, &block) ⇒ DelegateRule
constructor
Initialize with a set of rules and a prefix.
- #print_rule ⇒ Object
- #start(path, doc, node) ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ DelegateRule
Initialize with a set of rules and a prefix
33 34 35 36 37 |
# File 'lib/sawtooth/rules/delegate_rule.rb', line 33 def initialize( = {}, &block) self.path = [:path] self.rules = [:rules] self.prefix = [:prefix] || '' end |
Instance Attribute Details
#path ⇒ Object
Access the set of rules and prefix.
30 31 32 |
# File 'lib/sawtooth/rules/delegate_rule.rb', line 30 def path @path end |
#prefix ⇒ Object
Access the set of rules and prefix.
30 31 32 |
# File 'lib/sawtooth/rules/delegate_rule.rb', line 30 def prefix @prefix end |
#rules ⇒ Object
Access the set of rules and prefix.
30 31 32 |
# File 'lib/sawtooth/rules/delegate_rule.rb', line 30 def rules @rules end |
Instance Method Details
#before_after_callbacks_rule ⇒ Object
Builds a special rule which invokes :before and :after callbacks on the supplied set of rules.
41 42 43 |
# File 'lib/sawtooth/rules/delegate_rule.rb', line 41 def before_after_callbacks_rule @before_after_callbacks_rule ||= CallbacksRule.new(self) end |
#finish(path, doc, node) ⇒ Object
51 52 53 54 55 |
# File 'lib/sawtooth/rules/delegate_rule.rb', line 51 def finish(path, doc, node) new_path = relative_path(path) rule = rules && rules.find(new_path) rule.finish(new_path, doc, node) if rule && rule.respond_to?(:finish) end |
#print_rule ⇒ Object
57 58 59 60 61 62 |
# File 'lib/sawtooth/rules/delegate_rule.rb', line 57 def print_rule "#{self.class.name}, rules=[\n\t".tap do |str| str << rules.print_rules.split("\n").join("\n\t") << "\n" if rules && rules.respond_to?(:print_rules) str << "]" end end |
#start(path, doc, node) ⇒ Object
45 46 47 48 49 |
# File 'lib/sawtooth/rules/delegate_rule.rb', line 45 def start(path, doc, node) new_path = relative_path(path) rule = rules && rules.find(new_path) rule.start(new_path, doc, node) if rule && rule.respond_to?(:start) end |