module RenderSync::ModelActions
Attributes
sync_actions[RW]
Set up instance variable holding the collected sync actions to be published later on.
Public Class Methods
included(base)
click to toggle source
Set up ActiveRecord callbacks to prepare for collecting publish sync actions and publishing them after commit
# 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
Public Instance Methods
sync_default_scope()
click to toggle source
# 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
Private Instance Methods
add_sync_action(action_name, record, options = {})
click to toggle source
Add a new aync action to the list of actions to be published later on
# File lib/render_sync/model_actions.rb, line 40 def add_sync_action(action_name, record, options = {}) sync_actions.push(Action.new(record, action_name, options)) end
prepare_sync_actions()
click to toggle source
# File lib/render_sync/model_actions.rb, line 34 def prepare_sync_actions self.sync_actions = [] end
publish_sync_actions()
click to toggle source
Run the collected actions on after_commit callback Triggers the syncing of the partials
# File lib/render_sync/model_actions.rb, line 47 def publish_sync_actions sync_actions.each(&:perform) end
sync_render_context()
click to toggle source
Calls superclass method
# File lib/render_sync/model_actions.rb, line 30 def sync_render_context RenderSync::Model.context || super end
sync_scope_definitions()
click to toggle source
# File lib/render_sync/model_actions.rb, line 51 def sync_scope_definitions self.class.sync_scope_definitions.values end