Class: MicroBunny::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/microbunny/event.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel) ⇒ Event

Returns a new instance of Event.



13
14
15
# File 'lib/microbunny/event.rb', line 13

def initialize(channel)
  @channel = channel
end

Class Method Details

.exchange(name) ⇒ Object



7
8
9
10
11
# File 'lib/microbunny/event.rb', line 7

def self.exchange(name)
  define_method(:exchange) do
    name.to_sym
  end
end

Instance Method Details

#nameObject



30
31
32
# File 'lib/microbunny/event.rb', line 30

def name
  self.class.name.gsub(/Event$/, '')
end

#publish(message, record_id = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/microbunny/event.rb', line 17

def publish(message, record_id = nil)
  x = channel.topic(self.exchange)
  payload = build_payload(name, message)

  if record_id
    record = Record.new(record_id)
    payload.record = record.id
    x.publish(payload.serialize, routing_key: record.routing_key_for(self))
  else
    x.publish(payload.serialize, routing_key: name)
  end
end