Module: RenderSync::ModelActions

Defined in:
lib/render_sync/model_actions.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#sync_actionsObject

Set up instance variable holding the collected sync actions to be published later on.



6
7
8
# File 'lib/render_sync/model_actions.rb', line 6

def sync_actions
  @sync_actions
end

Class Method Details

.included(base) ⇒ Object

Set up ActiveRecord callbacks to prepare for collecting publish sync actions and publishing them after commit



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/render_sync/model_actions.rb', line 11

def self.included(base)
  base.class_eval do
    @sync_scope_definitions ||= {}
    
    before_create  :prepare_sync_actions, if: -> { RenderSync::Model.enabled? }
    before_update  :prepare_sync_actions, if: -> { RenderSync::Model.enabled? }
    before_destroy :prepare_sync_actions, if: -> { RenderSync::Model.enabled? }
    
    after_commit   :publish_sync_actions, if: -> { RenderSync::Model.enabled? }
  end
end

Instance Method Details

#sync_default_scopeObject



23
24
25
26
# File 'lib/render_sync/model_actions.rb', line 23

def sync_default_scope
  return nil unless self.class.sync_default_scope
  send self.class.sync_default_scope
end