Module: Alondra::ChangesCallbacks
- Extended by:
- ChangesCallbacks
- Included in:
- ChangesCallbacks
- Defined in:
- lib/alondra/changes_callbacks.rb
Instance Method Summary collapse
- #channel_names_from(type, record, options) ⇒ Object
- #push_creations(klass, options) ⇒ Object
- #push_destroys(klass, options) ⇒ Object
- #push_event(type, record, options) ⇒ Object
- #push_updates(klass, options) ⇒ Object
Instance Method Details
#channel_names_from(type, record, options) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/alondra/changes_callbacks.rb', line 40 def channel_names_from(type, record, ) case [:to] when String then [[:to]] when Symbol then records = record.send [:to] Channel.names_for(records) else [Channel.default_name_for(record)] end end |
#push_creations(klass, options) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/alondra/changes_callbacks.rb', line 13 def push_creations(klass, ) klass.class_eval do after_create do |record| ChangesCallbacks.push_event :created, record, end end end |
#push_destroys(klass, options) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/alondra/changes_callbacks.rb', line 21 def push_destroys(klass, ) klass.class_eval do after_destroy do |record| ChangesCallbacks.push_event :destroyed, record, end end end |
#push_event(type, record, options) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/alondra/changes_callbacks.rb', line 29 def push_event(type, record, ) channels = channel_names_from(type, record, ) channels.each do |channel| event = Event.new(:event => type, :resource => record, :resource_type => record.class.name, :channel => channel) MessageQueueClient.push event end end |
#push_updates(klass, options) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/alondra/changes_callbacks.rb', line 5 def push_updates(klass, ) klass.class_eval do after_update do |record| ChangesCallbacks.push_event :updated, record, end end end |