Module: AssetTimestampsCache

Defined in:
lib/asset_timestamps_cache.rb

Defined Under Namespace

Modules: ViewHelper

Constant Summary collapse

@@asset_timestamps_cache =
{}
@@asset_dir =
'public'

Class Method Summary collapse

Class Method Details

.[](asset_path) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/asset_timestamps_cache.rb', line 14

def self.[](asset_path)
  if timestamp = @@asset_timestamps_cache[asset_path]
    timestamp
  else
    file_path = File.join(*[@@asset_dir, asset_path].compact)
    timestamp = File.exist?(file_path) ? File.mtime(file_path).to_i.to_s : ''
    @@asset_timestamps_cache[asset_path] = timestamp
  end
end

.asset_dirObject



6
7
8
# File 'lib/asset_timestamps_cache.rb', line 6

def self.asset_dir
  @@asset_dir
end

.asset_dir=(val) ⇒ Object



10
11
12
# File 'lib/asset_timestamps_cache.rb', line 10

def self.asset_dir=(val)
  @@asset_dir = val
end

.clearObject



24
25
26
# File 'lib/asset_timestamps_cache.rb', line 24

def self.clear
  @@asset_timestamps_cache.clear
end

.timestamped_asset_path(asset_path) ⇒ Object



28
29
30
31
# File 'lib/asset_timestamps_cache.rb', line 28

def self.timestamped_asset_path(asset_path)
  timestamp = self[asset_path]
  "#{asset_path}?#{timestamp}"
end