Class: RenderSync::RefetchModel

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

Class Method Summary collapse

Class Method Details

.find_by_class_name_and_id(resource_name, id) ⇒ Object



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

def self.find_by_class_name_and_id(resource_name, id)      
  class_name = resource_name.to_s.classify
  class_name.safe_constantize.find(id) if supported_classes.include?(class_name)
rescue
  nil
end

.supported_classesObject



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

def self.supported_classes
  Thread.current["sync_refetch_classes"] = nil if Rails.env.development?
  
  Thread.current["sync_refetch_classes"] ||= begin
    Dir["app/views/sync/*/refetch"].collect{|path|
      File.basename(path.gsub(/\/refetch$/, '')).classify
    }.reject{|clazz| clazz.nil? }
  end
end