Class: Rake::Pipeline::Web::Filters::CacheBusterFilter
- Inherits:
-
Filter
- Object
- Filter
- Rake::Pipeline::Web::Filters::CacheBusterFilter
- Defined in:
- lib/rake-pipeline-web-filters/cache_buster_filter.rb
Overview
A filter that inserts a cache-busting key into the outputted file name.
Constant Summary collapse
- DEFAULT_KEY_GENERATOR =
Returns the default cache key generator, which takes the MD5 hash of the input’s file name and contents.
proc { |input| require 'digest/md5' Digest::MD5.new << input.path << input.read }
Instance Method Summary collapse
- #generate_output(inputs, output) ⇒ Object
-
#initialize(&key_generator) ⇒ CacheBusterFilter
constructor
A new instance of CacheBusterFilter.
Constructor Details
#initialize(&key_generator) ⇒ CacheBusterFilter
Returns a new instance of CacheBusterFilter.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rake-pipeline-web-filters/cache_buster_filter.rb', line 24 def initialize(&key_generator) key_generator ||= DEFAULT_KEY_GENERATOR output_name_generator = proc { |path, file| parts = path.split('.') index_to_modify = parts.length > 1 ? -2 : -1 parts[index_to_modify] << "-#{key_generator.call(file)}" parts.join('.') } super(&output_name_generator) end |
Instance Method Details
#generate_output(inputs, output) ⇒ Object
35 36 37 38 39 |
# File 'lib/rake-pipeline-web-filters/cache_buster_filter.rb', line 35 def generate_output(inputs, output) inputs.each do |input| output.write input.read end end |