Class: RenderSync::RefetchPartial

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

Instance Attribute Summary

Attributes inherited from Partial

#context, #name, #resource

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Partial

#auth_token, #authorized?, #channel_for_action, #channel_prefix, #initialize, #refetch_auth_token, #render, #render_to_string, #selector_end, #selector_start, #sync, #update_channel_prefix

Constructor Details

This class inherits a constructor from RenderSync::Partial

Class Method Details

.all(model, context, scope = nil) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/render_sync/refetch_partial.rb', line 4

def self.all(model, context, scope = nil)
  resource = Resource.new(model)

  Dir["#{RenderSync.views_root}/#{resource.plural_name}/refetch/_*.*"].map do |partial|
    partial_name = File.basename(partial)
    RefetchPartial.new(partial_name[1...partial_name.index('.')], resource.model, scope, context)
  end
end

.find(model, partial_name, context) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/render_sync/refetch_partial.rb', line 13

def self.find(model, partial_name, context)
  resource = Resource.new(model)
  plural_name = resource.plural_name
  partial = Dir["#{RenderSync.views_root}/#{plural_name}/refetch/_#{partial_name}.*"].first
  return unless partial
  RefetchPartial.new(partial_name, resource.model, nil, context)
end

.find_by_authorized_resource(model, partial_name, context, auth_token) ⇒ Object



21
22
23
24
25
26
# File 'lib/render_sync/refetch_partial.rb', line 21

def self.find_by_authorized_resource(model, partial_name, context, auth_token)
  partial = find(model, partial_name, context)
  return unless partial && partial.authorized?(auth_token)

  partial
end

Instance Method Details

#creator_for_scope(scope) ⇒ Object



32
33
34
# File 'lib/render_sync/refetch_partial.rb', line 32

def creator_for_scope(scope)
  RefetchPartialCreator.new(name, resource.model, scope, context)
end

#message(action) ⇒ Object



28
29
30
# File 'lib/render_sync/refetch_partial.rb', line 28

def message(action)
  RenderSync.client.build_message channel_for_action(action), refetch: true
end