Class: RequirejsOptimizer::Step::Digestify

Inherits:
Base
  • Object
show all
Defined in:
lib/requirejs_optimizer/step/digestify.rb

Instance Method Summary collapse

Methods inherited from Base

#to_proc

Constructor Details

#initializeDigestify

Returns a new instance of Digestify.



7
8
9
# File 'lib/requirejs_optimizer/step/digestify.rb', line 7

def initialize
  Rails.application.initialize!(:assets) unless Rails.application.assets.present?
end

Instance Method Details

#digestify_file(path) ⇒ Object



17
18
19
20
21
# File 'lib/requirejs_optimizer/step/digestify.rb', line 17

def digestify_file(path)
  digest = Rails.application.assets.file_digest(path).hexdigest
  new_path = path.gsub(/\.([^\.]*)$/) { "-#{digest}.#{$1}" }
  FileUtils.cp(path, new_path)
end

#performObject



11
12
13
14
15
# File 'lib/requirejs_optimizer/step/digestify.rb', line 11

def perform(*)
  RequirejsOptimizer.target_files.each do |f|
    digestify_file f
  end
end