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.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.digest(options) ⇒ Object
Supported options:.
Instance Method Summary collapse
- #dependencies ⇒ Object
- #digest ⇒ Object
-
#initialize(options) ⇒ Digestor
constructor
A new instance of Digestor.
- #nested_dependencies ⇒ Object
Constructor Details
#initialize(options) ⇒ Digestor
Returns a new instance of Digestor.
56 57 58 59 |
# File 'lib/action_view/digestor.rb', line 56 def initialize() @name, @finder = .values_at(:name, :finder) @options = .except(:name, :finder) end |
Instance Attribute Details
#finder ⇒ Object (readonly)
Returns the value of attribute finder.
54 55 56 |
# File 'lib/action_view/digestor.rb', line 54 def finder @finder end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
54 55 56 |
# File 'lib/action_view/digestor.rb', line 54 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
54 55 56 |
# File 'lib/action_view/digestor.rb', line 54 def @options end |
Class Method Details
.digest(options) ⇒ Object
Supported options:
-
name
- Template name -
finder
- An instance of ActionView::LookupContext -
dependencies
- An array of dependent views -
partial
- Specifies whether the template is a partial
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/action_view/digestor.rb', line 18 def digest() .assert_valid_keys(:name, :finder, :dependencies, :partial) cache_key = ([ [:name], [:finder].details_key.hash ].compact + 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, ) end end end |
Instance Method Details
#dependencies ⇒ Object
70 71 72 73 74 75 |
# File 'lib/action_view/digestor.rb', line 70 def dependencies DependencyTracker.find_dependencies(name, template) rescue ActionView::MissingTemplate logger.try :error, " '#{name}' file doesn't exist, so no dependencies" [] end |
#digest ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/action_view/digestor.rb', line 61 def digest Digest::MD5.hexdigest("#{source}-#{dependency_digest}").tap do |digest| logger.try :debug, " Cache digest for #{template.inspect}: #{digest}" end rescue ActionView::MissingTemplate logger.try :error, " Couldn't find template for digesting: #{name}" '' end |
#nested_dependencies ⇒ Object
77 78 79 80 81 82 |
# File 'lib/action_view/digestor.rb', line 77 def nested_dependencies dependencies.collect do |dependency| dependencies = PartialDigestor.new(name: dependency, finder: finder).nested_dependencies dependencies.any? ? { dependency => dependencies } : dependency end end |