Class: RenderSync::PartialCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/render_sync/partial_creator.rb

Direct Known Subclasses

RefetchPartialCreator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, resource, scopes, context) ⇒ PartialCreator

Returns a new instance of PartialCreator.



5
6
7
8
9
10
# 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

Instance Attribute Details

#contextObject

Returns the value of attribute context.



3
4
5
# File 'lib/render_sync/partial_creator.rb', line 3

def context
  @context
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/render_sync/partial_creator.rb', line 3

def name
  @name
end

#partialObject

Returns the value of attribute partial.



3
4
5
# File 'lib/render_sync/partial_creator.rb', line 3

def partial
  @partial
end

#resourceObject

Returns the value of attribute resource.



3
4
5
# File 'lib/render_sync/partial_creator.rb', line 3

def resource
  @resource
end

Instance Method Details

#auth_tokenObject



12
13
14
# File 'lib/render_sync/partial_creator.rb', line 12

def auth_token
  @auth_token ||= Channel.new("#{polymorphic_path}-_#{name}").to_s
end

#channelObject



16
17
18
# File 'lib/render_sync/partial_creator.rb', line 16

def channel
  @channel ||= auth_token
end

#messageObject



28
29
30
31
32
33
34
35
36
37
38
# 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

#selectorObject



20
21
22
# File 'lib/render_sync/partial_creator.rb', line 20

def selector
  "#{channel}"
end

#sync_newObject



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

def sync_new
  message.publish
end