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
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.
19 20 21 |
# File 'lib/action_view/digestor.rb', line 19 def initialize(name, format, finder, ={}) @name, @format, @finder, = name, format, finder, end |
Instance Attribute Details
#finder ⇒ Object (readonly)
Returns the value of attribute finder.
17 18 19 |
# File 'lib/action_view/digestor.rb', line 17 def finder @finder end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
17 18 19 |
# File 'lib/action_view/digestor.rb', line 17 def format @format end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/action_view/digestor.rb', line 17 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'lib/action_view/digestor.rb', line 17 def end |
Class Method Details
.digest(name, format, finder, options = {}) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/action_view/digestor.rb', line 9 def self.digest(name, format, finder, = {}) cache_key = [name, format] + Array.wrap([:dependencies]) @@cache[cache_key.join('.')] ||= begin klass = [:partial] || name.include?("/_") ? PartialDigestor : Digestor klass.new(name, format, finder, ).digest end end |
Instance Method Details
#dependencies ⇒ Object
32 33 34 35 36 |
# File 'lib/action_view/digestor.rb', line 32 def dependencies DependencyTracker.find_dependencies(name, template) rescue ActionView::MissingTemplate [] # File doesn't exist, so no dependencies end |
#digest ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/action_view/digestor.rb', line 23 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
38 39 40 41 42 43 |
# File 'lib/action_view/digestor.rb', line 38 def nested_dependencies dependencies.collect do |dependency| dependencies = PartialDigestor.new(dependency, format, finder).nested_dependencies dependencies.any? ? { dependency => dependencies } : dependency end end |