Class: Sawtooth::Rules::DelegateRule

Inherits:
Base
  • Object
show all
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

Instance Method Summary collapse

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(options = {}, &block)
  self.path = options[:path]
  self.rules = options[:rules]
  self.prefix = options[:prefix] || ''
end

Instance Attribute Details

#pathObject

Access the set of rules and prefix.



30
31
32
# File 'lib/sawtooth/rules/delegate_rule.rb', line 30

def path
  @path
end

#prefixObject

Access the set of rules and prefix.



30
31
32
# File 'lib/sawtooth/rules/delegate_rule.rb', line 30

def prefix
  @prefix
end

#rulesObject

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_ruleObject

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


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