class TmfCommon::Subscriber
Attributes
namespace[R]
Public Class Methods
attach_to(namespace)
click to toggle source
attach public methods of subscriber with events in the namespace
# File lib/tmf_common/subscriber.rb, line 10 def self.attach_to(namespace) log_subscriber = new(namespace) log_subscriber.public_methods(false).each do |event| ActiveSupport::Notifications.subscribe("#{namespace}.#{event}", log_subscriber) end end
new(namespace)
click to toggle source
# File lib/tmf_common/subscriber.rb, line 5 def initialize(namespace) @namespace = namespace end
Public Instance Methods
call(message, *args)
click to toggle source
trigger methods when an even is captured
# File lib/tmf_common/subscriber.rb, line 18 def call(message, *args) method = message.gsub("#{namespace}.", '') handler = self.class.new(namespace) handler.send(method, ActiveSupport::Notifications::Event.new(message, *args)) end