Class: ActionView::Digestor
- Inherits:
-
Object
- Object
- ActionView::Digestor
- Defined in:
- lib/action_view/digestor.rb
Direct Known Subclasses
Constant Summary collapse
- @@cache =
ThreadSafe::Cache.new
- @@digest_monitor =
Monitor.new
Instance Attribute Summary collapse
-
#finder ⇒ Object
readonly
Returns the value of attribute finder.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #dependencies ⇒ Object
- #digest ⇒ Object
-
#initialize(name, format, finder, options = {}) ⇒ Digestor
constructor
A new instance of Digestor.
- #nested_dependencies ⇒ Object
Constructor Details
#initialize(name, format, finder, options = {}) ⇒ Digestor
Returns a new instance of Digestor.
47 48 49 |
# File 'lib/action_view/digestor.rb', line 47 def initialize(name, format, finder, ={}) @name, @format, @finder, @options = name, format, finder, end |
Instance Attribute Details
#finder ⇒ Object (readonly)
Returns the value of attribute finder.
45 46 47 |
# File 'lib/action_view/digestor.rb', line 45 def finder @finder end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
45 46 47 |
# File 'lib/action_view/digestor.rb', line 45 def format @format end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
45 46 47 |
# File 'lib/action_view/digestor.rb', line 45 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
45 46 47 |
# File 'lib/action_view/digestor.rb', line 45 def @options end |
Class Method Details
.digest(name, format, finder, options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/action_view/digestor.rb', line 12 def digest(name, format, finder, = {}) cache_key = ([name, format] + Array.wrap([:dependencies])).join('.') # this is a correctly done double-checked locking idiom # (ThreadSafe::Cache's lookups have volatile semantics) @@cache[cache_key] || @@digest_monitor.synchronize do @@cache.fetch(cache_key) do # re-check under lock compute_and_store_digest(cache_key, name, format, finder, ) end end end |
Instance Method Details
#dependencies ⇒ Object
60 61 62 63 64 |
# File 'lib/action_view/digestor.rb', line 60 def dependencies DependencyTracker.find_dependencies(name, template) rescue ActionView::MissingTemplate [] # File doesn't exist, so no dependencies end |
#digest ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/action_view/digestor.rb', line 51 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_dependencies ⇒ Object
66 67 68 69 70 71 |
# File 'lib/action_view/digestor.rb', line 66 def nested_dependencies dependencies.collect do |dependency| dependencies = PartialDigestor.new(dependency, format, finder).nested_dependencies dependencies.any? ? { dependency => dependencies } : dependency end end |