Class: CacheDigests::TemplateDigestor
- Inherits:
-
Object
- Object
- CacheDigests::TemplateDigestor
- Defined in:
- lib/cache_digests/template_digestor.rb
Constant Summary collapse
- EXPLICIT_DEPENDENCY =
/# Template Dependency: ([^ ]+)/- RENDER_DEPENDENCY =
Matches:
render partial: "comments/comment", collection: commentable.comments render "comments/comments" render 'comments/comments' render('comments/comments') render(@topic) => render("topics/topic") render(topics) => render("topics/topic") render(message.topics) => render("topics/topic") / render\s? # render, followed by an optional space \(? # start a optional parenthesis for the render call (partial:)?\s? # naming the partial, used with collection -- 1st capture ([@a-z"'][@a-z_\/\."']+) # the template name itself -- 2nd capture /x
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 = {}) ⇒ TemplateDigestor
constructor
A new instance of TemplateDigestor.
- #nested_dependencies ⇒ Object
Constructor Details
#initialize(name, format, finder, options = {}) ⇒ TemplateDigestor
Returns a new instance of TemplateDigestor.
33 34 35 |
# File 'lib/cache_digests/template_digestor.rb', line 33 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.
31 32 33 |
# File 'lib/cache_digests/template_digestor.rb', line 31 def finder @finder end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
31 32 33 |
# File 'lib/cache_digests/template_digestor.rb', line 31 def format @format end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
31 32 33 |
# File 'lib/cache_digests/template_digestor.rb', line 31 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
31 32 33 |
# File 'lib/cache_digests/template_digestor.rb', line 31 def @options end |
Class Method Details
.digest(name, format, finder, options = {}) ⇒ Object
27 28 29 |
# File 'lib/cache_digests/template_digestor.rb', line 27 def self.digest(name, format, finder, = {}) cache["#{name}.#{format}"] ||= new(name, format, finder, ).digest end |
Instance Method Details
#dependencies ⇒ Object
46 47 48 49 50 |
# File 'lib/cache_digests/template_digestor.rb', line 46 def dependencies render_dependencies + explicit_dependencies rescue ActionView::MissingTemplate [] # File doesn't exist, so no dependencies end |
#digest ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/cache_digests/template_digestor.rb', line 37 def digest Digest::MD5.hexdigest("#{name}.#{format}-#{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
52 53 54 55 56 57 |
# File 'lib/cache_digests/template_digestor.rb', line 52 def nested_dependencies dependencies.collect do |dependency| dependencies = TemplateDigestor.new(dependency, format, finder, partial: true).nested_dependencies dependencies.any? ? { dependency => dependencies } : dependency end end |