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

Version Path
fullstack-cms-0.3.25 app/support/subscriber.rb
fullstack-cms-0.3.24 app/support/subscriber.rb
fullstack-cms-0.3.23 app/support/subscriber.rb
fullstack-cms-0.3.22 app/support/subscriber.rb
fullstack-cms-0.3.21 app/support/subscriber.rb
fullstack-cms-0.3.20 app/support/subscriber.rb
fullstack-cms-0.3.19 app/support/subscriber.rb
fullstack-cms-0.3.18 app/support/subscriber.rb
fullstack-cms-0.3.17 app/support/subscriber.rb
fullstack-cms-0.3.16 app/support/subscriber.rb
fullstack-cms-0.3.15 app/support/subscriber.rb
fullstack-cms-0.3.14 app/support/subscriber.rb
fullstack-cms-0.3.13 app/support/subscriber.rb
fullstack-cms-0.3.12 app/support/subscriber.rb
fullstack-cms-0.3.11 app/support/subscriber.rb