class RenderSync::PartialCreator

Attributes

context[RW]
name[RW]
partial[RW]
resource[RW]

Public Class Methods

new(name, resource, scopes, context) click to toggle source
# File lib/render_sync/partial_creator.rb, line 5
def initialize(name, resource, scopes, context)
  self.name = name
  self.resource = Resource.new(resource, scopes)
  self.context = context
  self.partial = Partial.new(name, self.resource.model, scopes, context)
end

Public Instance Methods

auth_token() click to toggle source
# File lib/render_sync/partial_creator.rb, line 12
def auth_token
  @auth_token ||= Channel.new("#{polymorphic_path}-_#{name}").to_s
end
channel() click to toggle source
# File lib/render_sync/partial_creator.rb, line 16
def channel
  @channel ||= auth_token
end
message() click to toggle source
# File lib/render_sync/partial_creator.rb, line 28
def message
  RenderSync.client.build_message(channel,
    html: partial.render_to_string,
    resourceId: resource.id,
    authToken: partial.auth_token,
    channelUpdate: partial.channel_for_action(:update),
    channelDestroy: partial.channel_for_action(:destroy),
    selectorStart: partial.selector_start,
    selectorEnd: partial.selector_end
  )
end
selector() click to toggle source
# File lib/render_sync/partial_creator.rb, line 20
def selector
  "#{channel}"
end
sync_new() click to toggle source
# File lib/render_sync/partial_creator.rb, line 24
def sync_new
  message.publish
end

Private Instance Methods

polymorphic_path() click to toggle source
# File lib/render_sync/partial_creator.rb, line 43
def polymorphic_path
  resource.polymorphic_new_path
end