Sha256: 70e3e8408353b242d1f0c862e4b0df8f823d7d496d37e9abd10df7be0deae910
Contents?: true
Size: 837 Bytes
Versions: 35
Compression:
Stored size: 837 Bytes
Contents
class Subscriber class Event def initialize(hash) hash.each do |k,v| self.instance_variable_set("@#{k}", v) ## create and initialize an instance variable for this key/value pair self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")}) ## create the getter that returns the instance variable self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{k}", v)}) ## create the setter that sets the instance variable end end end class << self def on(*events, &block) instance = @instance ||= self.new events.each do |event| ActiveSupport::Notifications.subscribe( event ) do |name, start, finish, id, payload| instance.instance_exec(Event.new(payload), &block) end end end end end
Version data entries
35 entries across 35 versions & 1 rubygems