Class: ActionView::Digestor
- Defined in:
- actionview/lib/action_view/digestor.rb
Direct Known Subclasses
Constant Summary collapse
- @@cache =
ThreadSafe::Cache.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.
23 24 25 |
# File 'actionview/lib/action_view/digestor.rb', line 23 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
21 22 23 |
# File 'actionview/lib/action_view/digestor.rb', line 21 def finder @finder end |
#format ⇒ Object (readonly)
Returns the value of attribute format
21 22 23 |
# File 'actionview/lib/action_view/digestor.rb', line 21 def format @format end |
#name ⇒ Object (readonly)
Returns the value of attribute name
21 22 23 |
# File 'actionview/lib/action_view/digestor.rb', line 21 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options
21 22 23 |
# File 'actionview/lib/action_view/digestor.rb', line 21 def @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, = {}) cache_key = ([name, format] + Array.wrap([:dependencies])).join('.') @@cache.fetch(cache_key) do @@cache[cache_key] ||= nil if [:partial] # Prevent re-entry klass = [:partial] || name.include?("/_") ? PartialDigestor : Digestor digest = klass.new(name, format, finder, ).digest @@cache[cache_key] = digest # Store the value end end |
Instance Method Details
#dependencies ⇒ Object
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 |
#digest ⇒ Object
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_dependencies ⇒ Object
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 |