Sha256: fd38626375d7deafb70f79890e3768d205e32d3c6df98d843cdb745de4f10e00
Contents?: true
Size: 1012 Bytes
Versions: 1
Compression:
Stored size: 1012 Bytes
Contents
module PubSub class ActiveRecordExtensions < Rails::Railtie initializer "pub sub configuration of active record extensions" do class ::ActiveRecord::Base after_create :notify_of_after_create private def notify_of_after_create notify_pub_sub_of_active_record_callback('after_create') end def notify_pub_sub_of_active_record_callback(callback) message = "active_record::#{self.class.to_s.underscore}::#{callback}" PubSub.publish(message, record: self) end end config.after_initialize do Dir[ File.expand_path("app/models/pub_sub/*.rb", Rails.root) ].each { |file| require file } end end end module ActiveRecord class Subscriber < PubSub::Subscriber def self.subscribe_to(class_instance, callback) super("active_record::#{class_instance.to_s.underscore}::#{callback}") end def record options[:record] end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ruby_pub_sub-0.0.4 | lib/pub_sub/active_record_extensions.rb |