class MicroBunny::Record
Attributes
label[R]
record[R]
settings[R]
Public Class Methods
new(record, settings = MicroBunny.settings)
click to toggle source
# File lib/microbunny/record.rb, line 5 def initialize(record, settings = MicroBunny.settings) @record = record @label = extract_label(record) @settings = settings end
Public Instance Methods
address()
click to toggle source
# File lib/microbunny/record.rb, line 29 def address "#{settings.consumer_app}-#{label}" end
id()
click to toggle source
# File lib/microbunny/record.rb, line 11 def id if string? record elsif active_record? record.id else raise_invalid_record end end
routing_key_for(event)
click to toggle source
# File lib/microbunny/record.rb, line 25 def routing_key_for(event) "#{event.name}.#{label}" end
routing_key_matcher()
click to toggle source
# File lib/microbunny/record.rb, line 21 def routing_key_matcher "*.#{label}" end
Private Instance Methods
active_record?()
click to toggle source
# File lib/microbunny/record.rb, line 47 def active_record? record.is_a? ActiveRecord::Base end
activerecord_label()
click to toggle source
# File lib/microbunny/record.rb, line 51 def activerecord_label "#{record.class.name.downcase}-#{record.id}" end
extract_label(record)
click to toggle source
# File lib/microbunny/record.rb, line 37 def extract_label(record) return record if string? return activerecord_label if active_record? raise_invalid_record end
raise_invalid_record()
click to toggle source
# File lib/microbunny/record.rb, line 55 def raise_invalid_record raise "A record must be either a String or an ActiveRecord object" end
string?()
click to toggle source
# File lib/microbunny/record.rb, line 43 def string? record.is_a? String end