Class: Alchemy::CacheDigests::TemplateTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/alchemy/cache_digests/template_tracker.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, template) ⇒ TemplateTracker

Returns a new instance of TemplateTracker.



10
11
12
# File 'lib/alchemy/cache_digests/template_tracker.rb', line 10

def initialize(name, template)
  @name, @template = name, template
end

Class Method Details

.call(name, template) ⇒ Object



6
7
8
# File 'lib/alchemy/cache_digests/template_tracker.rb', line 6

def self.call(name, template)
  new(name, template).dependencies
end

Instance Method Details

#dependenciesObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/alchemy/cache_digests/template_tracker.rb', line 14

def dependencies
  case @name.to_s
  when /^alchemy\/pages\/show/
    PageLayout.all.map { |p| "alchemy/page_layouts/_#{p["name"]}" }
  when /^alchemy\/page_layouts\/_(\w+)/
    page_layout = PageLayout.get($1)
    layout_elements = page_layout.fetch("elements", [])
    layout_elements.map { |name| "alchemy/elements/_#{name}" }
  when /^alchemy\/elements\/_(\w+)/
    ingredient_types($1).map { |type|
      "alchemy/ingredients/_#{type.underscore}_view"
    }.uniq
  else
    ActionView::DependencyTracker::ERBTracker.call(@name, @template)
  end
end