Class: ActionView::Digestor

Inherits:
Object show all
Defined in:
actionview/lib/action_view/digestor.rb

Direct Known Subclasses

PartialDigestor

Constant Summary collapse

@@cache =
ThreadSafe::Cache.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, format, finder, options = {}) ⇒ Digestor

Returns a new instance of Digestor.



23
24
25
# File 'actionview/lib/action_view/digestor.rb', line 23

def initialize(name, format, finder, options={})
  @name, @format, @finder, @options = name, format, finder, options
end

Instance Attribute Details

#finderObject (readonly)

Returns the value of attribute finder



21
22
23
# File 'actionview/lib/action_view/digestor.rb', line 21

def finder
  @finder
end

#formatObject (readonly)

Returns the value of attribute format



21
22
23
# File 'actionview/lib/action_view/digestor.rb', line 21

def format
  @format
end

#nameObject (readonly)

Returns the value of attribute name



21
22
23
# File 'actionview/lib/action_view/digestor.rb', line 21

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options



21
22
23
# File 'actionview/lib/action_view/digestor.rb', line 21

def options
  @options
end

Class Method Details

.digest(name, format, finder, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'actionview/lib/action_view/digestor.rb', line 9

def self.digest(name, format, finder, options = {})
  cache_key = ([name, format] + Array.wrap(options[:dependencies])).join('.')
  @@cache.fetch(cache_key) do
    @@cache[cache_key] ||= nil if options[:partial] # Prevent re-entry

    klass = options[:partial] || name.include?("/_") ? PartialDigestor : Digestor
    digest = klass.new(name, format, finder, options).digest

    @@cache[cache_key] = digest # Store the value
  end
end

Instance Method Details

#dependenciesObject



36
37
38
39
40
# File 'actionview/lib/action_view/digestor.rb', line 36

def dependencies
  DependencyTracker.find_dependencies(name, template)
rescue ActionView::MissingTemplate
  [] # File doesn't exist, so no dependencies
end

#digestObject



27
28
29
30
31
32
33
34
# File 'actionview/lib/action_view/digestor.rb', line 27

def digest
  Digest::MD5.hexdigest("#{source}-#{dependency_digest}").tap do |digest|
    logger.try :info, "Cache digest for #{name}.#{format}: #{digest}"
  end
rescue ActionView::MissingTemplate
  logger.try :error, "Couldn't find template for digesting: #{name}.#{format}"
  ''
end

#nested_dependenciesObject



42
43
44
45
46
47
# File 'actionview/lib/action_view/digestor.rb', line 42

def nested_dependencies
  dependencies.collect do |dependency|
    dependencies = PartialDigestor.new(dependency, format, finder).nested_dependencies
    dependencies.any? ? { dependency => dependencies } : dependency
  end
end