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.4.6 app/support/subscriber.rb
fullstack-cms-0.4.5 app/support/subscriber.rb
fullstack-cms-0.4.4 app/support/subscriber.rb
fullstack-cms-0.4.3 app/support/subscriber.rb
fullstack-cms-0.4.2 app/support/subscriber.rb
fullstack-cms-0.4.1 app/support/subscriber.rb
fullstack-cms-0.3.39 app/support/subscriber.rb
fullstack-cms-0.3.38 app/support/subscriber.rb
fullstack-cms-0.3.37 app/support/subscriber.rb
fullstack-cms-0.3.36 app/support/subscriber.rb
fullstack-cms-0.3.35 app/support/subscriber.rb
fullstack-cms-0.3.34 app/support/subscriber.rb
fullstack-cms-0.3.33 app/support/subscriber.rb
fullstack-cms-0.3.32 app/support/subscriber.rb
fullstack-cms-0.3.31 app/support/subscriber.rb
fullstack-cms-0.3.30 app/support/subscriber.rb
fullstack-cms-0.3.29 app/support/subscriber.rb
fullstack-cms-0.3.28 app/support/subscriber.rb
fullstack-cms-0.3.27 app/support/subscriber.rb
fullstack-cms-0.3.26 app/support/subscriber.rb