module Qpid::Proton::Filters::ClassMethods

Public Instance Methods

call_before(before_method, *methods) click to toggle source
# File lib/qpid_proton/filters.rb, line 51
def call_before(before_method, *methods)
  @@before_hooks ||= {}
  methods.each do |method|
    hooks = @@before_hooks[method] || []
    raise "Repeat filter: #{before_method}" if hooks.include? before_method
    hooks << before_method
    @@before_hooks[method] = hooks
  end
end
method_added(method_name) click to toggle source
# File lib/qpid_proton/filters.rb, line 34
def method_added(method_name)
  @@hooked_methods ||= []
  return if @@hooked_methods.include?(method_name)
  @@hooked_methods << method_name
  hooks = @@before_hooks[method_name]
  return if hooks.nil?
  orig_method = instance_method(method_name)
  define_method(method_name) do |*args, &block|
    hooks = @@before_hooks[method_name]
    hooks.each do |hook|
      method(hook).call
    end

    orig_method.bind(self).call(*args, &block)
  end
end