Class: ChimpSync::Subscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/chimp_sync/subscriber.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, &block) ⇒ Subscriber

Returns a new instance of Subscriber.



10
11
12
# File 'lib/chimp_sync/subscriber.rb', line 10

def initialize(type, &block)
  @type, @block = type, block
end

Class Method Details

.add(*types, &block) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/chimp_sync/subscriber.rb', line 2

def self.add(*types, &block)
  types.each do |type|
    ActiveSupport::Notifications.subscribe("#{type}.panthoot") do |*args|
      new(type, &block).call *args
    end
  end
end

Instance Method Details

#call(*arguments) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/chimp_sync/subscriber.rb', line 14

def call(*arguments)
  data = ActiveSupport::Notifications::Event.new(*arguments).payload[type]

  ChimpSync.lists_for(data.list_id).each do |list|
    block.call list, data
  end
end