module Cony::ActiveRecord
Usage: <code> class FooBar < ActiveRecord::Base
include Cony::ActiveRecord # your things here
end </code>
Public Instance Methods
cony_publish()
click to toggle source
# File lib/cony/active_record.rb, line 39 def cony_publish return if Cony.config.test_mode return if @cony_notify.nil? cony_amqp_connection.publish(cony_notify_hash, cony_notify_routing_key) end
cony_save_create_notify_data()
click to toggle source
# File lib/cony/active_record.rb, line 27 def cony_save_create_notify_data cony_prepare_notify :created, cony_changes_created end
cony_save_destroy_notify_data()
click to toggle source
# File lib/cony/active_record.rb, line 35 def cony_save_destroy_notify_data cony_prepare_notify :destroyed, cony_changes_destroyed end
cony_save_update_notify_data()
click to toggle source
# File lib/cony/active_record.rb, line 31 def cony_save_update_notify_data cony_prepare_notify :updated, cony_changes_updated end
Private Instance Methods
cony_amqp_connection()
click to toggle source
# File lib/cony/active_record.rb, line 47 def cony_amqp_connection @cony_amqp_connection ||= Cony::AMQPConnectionHandler.new(Cony.config.amqp) end
cony_changes()
click to toggle source
# File lib/cony/active_record.rb, line 51 def cony_changes return saved_changes if respond_to? :saved_changes changes end
cony_changes_created()
click to toggle source
# File lib/cony/active_record.rb, line 62 def cony_changes_created cony_mapped_changes end
cony_changes_destroyed()
click to toggle source
# File lib/cony/active_record.rb, line 70 def cony_changes_destroyed attributes.map do |name, value| { name => { old: value, new: nil } } end end
cony_changes_updated()
click to toggle source
# File lib/cony/active_record.rb, line 66 def cony_changes_updated cony_mapped_changes end
cony_mapped_changes()
click to toggle source
# File lib/cony/active_record.rb, line 56 def cony_mapped_changes cony_changes.map do |name, change| { name => { old: change.first, new: change.last } } end end
cony_notify_hash()
click to toggle source
# File lib/cony/active_record.rb, line 76 def cony_notify_hash { id: id, changes: @cony_notify[:changes], model: self.class.name, event: @cony_notify[:event] } end
cony_notify_routing_key()
click to toggle source
# File lib/cony/active_record.rb, line 80 def cony_notify_routing_key "#{self.class.name.underscore}.mutation.#{@cony_notify[:event]}" end
cony_prepare_notify(event, changes)
click to toggle source
# File lib/cony/active_record.rb, line 84 def cony_prepare_notify(event, changes) @cony_notify = { event: event, changes: changes } end