class Temple::Mixins::CompiledDispatcher::DispatchNode

@api private

Attributes

method[RW]

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/temple/mixins/dispatcher.rb, line 81
def initialize
  super { |hsh,key| hsh[key] = DispatchNode.new }
  @method = nil
end

Public Instance Methods

compile(level = 0, call_parent = nil) click to toggle source
# File lib/temple/mixins/dispatcher.rb, line 86
def compile(level = 0, call_parent = nil)
  call_method = method ? (level == 0 ? "#{method}(*exp)" :
                          "#{method}(*exp[#{level}..-1])") : call_parent
  if empty?
    raise 'Invalid dispatcher node' unless method
    call_method
  else
    code = "case(exp[#{level}])\n"
    each do |key, child|
      code << "when #{key.inspect}\n  " <<
        child.compile(level + 1, call_method).gsub("\n".freeze, "\n  ".freeze) << "\n".freeze
    end
    code << "else\n  " << (call_method || 'exp') << "\nend"
  end
end