Module: MicroBunny

Defined in:
lib/microbunny.rb,
lib/microbunny/event.rb,
lib/microbunny/record.rb,
lib/microbunny/payload.rb,
lib/microbunny/settings.rb,
lib/microbunny/connection.rb,
lib/microbunny/subscriber.rb,
lib/microbunny/event_lookup.rb,
lib/microbunny/event_trigger.rb,
lib/microbunny/subscriptions.rb

Defined Under Namespace

Classes: Connection, Event, EventLookup, EventTrigger, Payload, Record, Settings, Subscriber, Subscriptions

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.channelObject

Returns the value of attribute channel.



15
16
17
# File 'lib/microbunny.rb', line 15

def channel
  @channel
end

.connectionObject

Returns the value of attribute connection.



15
16
17
# File 'lib/microbunny.rb', line 15

def connection
  @connection
end

.settingsObject

Returns the value of attribute settings.



15
16
17
# File 'lib/microbunny.rb', line 15

def settings
  @settings
end

Class Method Details

.configure {|settings| ... } ⇒ Object

Yields:



17
18
19
20
# File 'lib/microbunny.rb', line 17

def configure
  self.settings ||= Settings.new
  yield(settings)
end

.event(name) ⇒ Object



48
49
50
# File 'lib/microbunny.rb', line 48

def event(name)
  EventTrigger.new(channel, name)
end

.startObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/microbunny.rb', line 22

def start
  self.connection = Connection.new(
    host: self.settings.host,
    vhost: self.settings.vhost,
    username: self.settings.username,
    password: self.settings.password
  )
  
  self.channel = self.connection.channel
end

.stopObject



33
34
35
# File 'lib/microbunny.rb', line 33

def stop
  self.connection.stop
end

.subscribe(topics, record_ids = []) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/microbunny.rb', line 37

def subscribe(topics, record_ids = [])
  raise_bad_start unless self.channel

  records = record_ids.map(&Record.method(:new))
  subs = Subscriptions.new(self.channel, topics, records) do |payload|
    handle(payload) 
  end

  subs.create
end