Module: RenderSync::Actions
- Included in:
- Action, ControllerHelpers
- Defined in:
- lib/render_sync/actions.rb
Instance Method Summary collapse
-
#sync(resource, action, options = {}) ⇒ Object
Render all sync’d partials for resource to string and publish action to pubsub server with rendered resource messages.
-
#sync_destroy(resource, options = {}) ⇒ Object
Render all sync’d partials for resource to string and publish destroy action to pubsub server with rendered resource messages.
-
#sync_new(resource, options = {}) ⇒ Object
Render all sync’d partials for resource to string and publish new action to pubsub server with rendered resource messages.
-
#sync_update(resource, options = {}) ⇒ Object
Render all sync’d partials for resource to string and publish update action to pubsub server with rendered resource messages.
Instance Method Details
#sync(resource, action, options = {}) ⇒ Object
Render all sync’d partials for resource to string and publish action to pubsub server with rendered resource messages
resource - The ActiveModel resource action - The Symbol action to publish. One of :update, :destroy options - The Hash of options
default_scope - The ActiveModel resource to scope the action channel to
scope - Either a String, a symbol, an instance of ActiveModel or
RenderSync::Scope or an Array containing a combination to scope
the channel to. Will be concatenated to an optional default_scope
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/render_sync/actions.rb', line 45 def sync(resource, action, = {}) scope = [:scope] partial_name = [:partial] resources = [resource].flatten = resources.collect do |resource| if partial_name specified_partials(resource, sync_render_context, partial_name).collect do |partial| partial.(action) end else all_partials(resource, sync_render_context, scope).collect do |partial| partial.(action) end end end RenderSync.client.batch_publish(.flatten) end |
#sync_destroy(resource, options = {}) ⇒ Object
Render all sync’d partials for resource to string and publish destroy action to pubsub server with rendered resource messages
resource - The ActiveModel resource options - The Hash of options
default_scope - The ActiveModel resource to scope the update channel to
scope - Either a String, a symbol, an instance of ActiveModel or
RenderSync::Scope or an Array containing a combination to scope
the destroy channel to. Will be concatenated to an optional
default_scope
30 31 32 |
# File 'lib/render_sync/actions.rb', line 30 def sync_destroy(resource, = {}) sync resource, :destroy, end |
#sync_new(resource, options = {}) ⇒ Object
Render all sync’d partials for resource to string and publish new action to pubsub server with rendered resource messages
resource - The ActiveModel resource, or Array of ActiveModel resources action - The Symbol action to publish. One of :update, :destroy options - The Hash of options
default_scope - The ActiveModel resource to scope the new channel to
scope - Either a String, a symbol, an instance of ActiveModel or
RenderSync::Scope or an Array containing any combination to scope
the new channel to. Will be concatenated to an optional
default_scope
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/render_sync/actions.rb', line 76 def sync_new(resource, = {}) scope = [:scope] partial_name = [:partial] resources = [resource].flatten = resources.collect do |resource| if partial_name specified_partials(resource, sync_render_context, partial_name).collect do |partial| partial.creator_for_scope(scope). end else all_partials(resource, sync_render_context, scope).collect do |partial| partial.creator_for_scope(scope). end end end RenderSync.client.batch_publish(.flatten) end |
#sync_update(resource, options = {}) ⇒ Object
Render all sync’d partials for resource to string and publish update action to pubsub server with rendered resource messages
resource - The ActiveModel resource options - The Hash of options
default_scope - The ActiveModel resource to scope the update channel to
scope - Either a String, a symbol, an instance of ActiveModel or
RenderSync::Scope or an Array containing a combination to scope
the update channel to. Will be concatenated to an optional
default_scope
15 16 17 |
# File 'lib/render_sync/actions.rb', line 15 def sync_update(resource, = {}) sync resource, :update, end |