Module: Qpid::Proton::Filters::ClassMethods

Defined in:
lib/qpid_proton/filters.rb

Instance Method Summary collapse

Instance Method Details

#call_before(before_method, *methods) ⇒ Object



51
52
53
54
55
56
57
58
59
# 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) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 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