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(.topics) => render("topics/topic") / render\s* # render, followed by optional whitespace \(? # start an optional parenthesis for the render call (partial:|:partial\s+=>)?\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.
38 39 40 |
# File 'lib/cache_digests/template_digestor.rb', line 38 def initialize(name, format, finder, = {}) @name, @format, @finder, = name, format, finder, end |
Instance Attribute Details
#finder ⇒ Object (readonly)
Returns the value of attribute finder.
36 37 38 |
# File 'lib/cache_digests/template_digestor.rb', line 36 def finder @finder end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
36 37 38 |
# File 'lib/cache_digests/template_digestor.rb', line 36 def format @format end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
36 37 38 |
# File 'lib/cache_digests/template_digestor.rb', line 36 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
36 37 38 |
# File 'lib/cache_digests/template_digestor.rb', line 36 def end |
Class Method Details
.digest(name, format, finder, options = {}) ⇒ Object
30 31 32 33 34 |
# File 'lib/cache_digests/template_digestor.rb', line 30 def self.digest(name, format, finder, = {}) cache.fetch([ "digestor", cache_prefix, name, format ].compact.join("/")) do new(name, format, finder, ).digest end end |
Instance Method Details
#dependencies ⇒ Object
51 52 53 54 55 |
# File 'lib/cache_digests/template_digestor.rb', line 51 def dependencies render_dependencies + explicit_dependencies rescue ActionView::MissingTemplate [] # File doesn't exist, so no dependencies end |
#digest ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/cache_digests/template_digestor.rb', line 42 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
57 58 59 60 61 62 |
# File 'lib/cache_digests/template_digestor.rb', line 57 def nested_dependencies dependencies.collect do |dependency| dependencies = TemplateDigestor.new(dependency, format, finder, partial: true).nested_dependencies dependencies.any? ? { dependency => dependencies } : dependency end end |