Sha256: edd44859c7d65e5925f78d10850fc9013bd1c1beb6fa4fed6cf196a79f410e33

Contents?: true

Size: 817 Bytes

Versions: 8

Compression:

Stored size: 817 Bytes

Contents

class Reactor::Subscriber < ActiveRecord::Base
  attr_accessible :event
  attr_accessor :message

  def event=(event)
    write_attribute :event, event.to_s
  end

  def fire(data)
    self.message = Reactor::Event.new(data)
    instance_exec &self.class.on_fire
    self
  end

  def delay_amount
    self.class.delay_amount
  end

  class << self
    def on_fire(&block)
      if block
        @fire_block = block
      end
      @fire_block
    end

    def fire(subscriber_id, data)
      Reactor::Subscriber.find(subscriber_id).fire data
    end

    def subscribes_to(name = nil, delay: nil)
      @delay_amount = delay
      #subscribers << name
      #TODO: REMEMBER SUBSCRIBERS so we can define them in code as well as with a row in the DB
    end

    def delay_amount
      @delay_amount
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
reactor-0.2.2 lib/reactor/models/subscriber.rb
reactor-0.2.1 lib/reactor/models/subscriber.rb
reactor-0.2.0 lib/reactor/models/subscriber.rb
reactor-0.1.4 lib/reactor/models/subscriber.rb
reactor-0.1.3 lib/reactor/models/subscriber.rb
reactor-0.1.2 lib/reactor/models/subscriber.rb
reactor-0.1.1 lib/reactor/models/subscriber.rb
reactor-0.1.0 lib/reactor/models/subscriber.rb