Class: Sprockets::Base

Inherits:
Object show all
Defined in:
lib/volt/server/template_handlers/sprockets_component_handler.rb

Instance Method Summary collapse

Instance Method Details

#file_digest(path) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/volt/server/template_handlers/sprockets_component_handler.rb', line 115

def file_digest(path)
  if stat = self.stat(path)
    # Caveat: Digests are cached by the path's current mtime. Its possible
    # for a files contents to have changed and its mtime to have been
    # negligently reset thus appearing as if the file hasn't changed on
    # disk. Also, the mtime is only read to the nearest second. Its
    # also possible the file was updated more than once in a given second.
    cache.fetch("file_digest:#{path}:#{stat.mtime.to_i}") do
      self.stat_digest(path, stat)
    end
  elsif path =~ /^#{Volt.root}\/app\/components\/[^\/]+$/
    # Return a random mtime
    # puts "LMT: #{Volt::Dispatcher.last_modified_time.inspect}"
    mtime = Volt::Dispatcher.component_last_modified_time.to_s

    # puts "STUB: #{mtime}"
    "stub-digest-#{mtime}"
  end
end