Skip to content

Instantly share code, notes, and snippets.

@mwean
Created Sep 30, 2012
Embed
What would you like to do?
Examples of ConsumerPublisher
class ConsumerChangesObserver < ActiveRecord::Observer
observe :consumer, :address_record, :consumer_enrollment
def after_update(record)
ConsumerPublisher.publish_change(record)
end
end
class SomeController < FmsController
def some_action
consumer = Consumer.find(params[:consumer_id])
consumer.died!(params[:date])
ConsumerPublisher.consumer_died(consumer)
end
end
class ConsumerPublisher
extend Observable
def self.send_notification(consumer_id, values)
changed
notify_observers(consumer_id, values)
end
def self.publish_change(record)
if record.is_a?(Consumer) && record.has_some_meaningful_change?
values = {
first_name: record.first_name,
last_name: record.last_name,
date_of_birth: record.date_of_birth
}
send_notification(record.id, values)
else
# Other stuff
end
end
def self.consumer_died(consumer)
values = {
date_of_death: consumer.date_of_death
}
send_notification(consumer.id, values)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment