Class: XML::Digester::SetNextRule

Inherits:
LinkRule show all
Defined in:
lib/xml/digestr.rb

Overview

Rule that allows a parent -> child relationship to be created between the top two stack elements via a given method call. This is a specialized LinkRule that calls a method on the next-to-top stack element, passing in the top element as an argument. Often, the called method will have a name like ‘add_child’.

Like LinkRule, this rule operates in the end event. See also SetTopRule.

Instance Attribute Summary

Attributes inherited from RulesBase

#digester, #next, #pattern, #prev

Instance Method Summary collapse

Methods inherited from LinkRule

#end

Methods inherited from RulesBase

#begin, #body, #end, #finish

Constructor Details

#initialize(pattern, msg, *args) ⇒ SetNextRule

call-seq:

SetNextRule.new(pattern, msg, *additional_args)

Create a new SetNextRule that will send the specified message to the next-to-top stack object, passing in the top object as the initial parameter, followed by any additional arguments supplied to this method.



327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/xml/digestr.rb', line 327

def initialize(pattern, msg, *args)
  super(pattern) do |parent, child| 
    begin
      parent.send(msg, child, *args) 
    rescue NoMethodError
      if digester.pedantic?
        raise Error,
            "Cannot SetNext: no method #{msg} for #{parent.inspect}"
      end
      nil
    end
  end
end