class Tengine::Core::Handler

イベントハンドラ

Tengineコアは、イベントを受信するとそのイベント種別名にマッチするイベントハンドラを探して 見つかったイベントハンドラをすべて実行します。

Public Instance Methods

fire(event_type_name) click to toggle source
# File lib/tengine/core/handler.rb, line 88
def fire(event_type_name)
  @caller.fire(event_type_name)
end
match?(event) click to toggle source
# File lib/tengine/core/handler.rb, line 92
def match?(event)
  result = filter.blank? ? true : Visitor.new(filter, event, driver.session).visit
  Tengine.logger.debug("match?(#{event.event_type_name.inspect}) => #{result.inspect}")
  result
end
process_event(event) click to toggle source

def process_event(event, &block)

@caller = eval("self", block.binding)
matched = match?(event)
if matched
  # ハンドラの実行
  @caller.__safety_driver__(self.driver) do
    @caller.__safety_event__(event) do
      @caller.instance_eval(&block)
    end
  end
end

ensure

@caller = nil

end

# File lib/tengine/core/handler.rb, line 69
def process_event(event)
  case self.target_instantiation_key
  when :instance_method then
    klass = driver.target_class_name.constantize
    inst = klass.new
    inst.instance_variable_set(:@__event__, event)
    m = inst.method(target_method_name)
    m.arity == 0 ? m.call : m.call(event)
  when :static then
    klass = driver.target_class_name.constantize
    m = klass.method(target_method_name)
    m.arity == 0 ? m.call : m.call(event)
  when :binding then
    # do nothing
  else
    raise Tengine::Core::KernelError, "Unsupported target_instantiation_key: #{self.target_instantiation_key.inspect}"
  end
end
update_handler_path() click to toggle source
# File lib/tengine/core/handler.rb, line 47
def update_handler_path
  event_type_names.each do |event_type_name|
    Tengine::Core::HandlerPath.create!(:event_type_name => event_type_name,
      :driver_id => self.driver.id, :handler_id => self.id)
  end
end