Created
May 30, 2012 23:01
-
-
Save Kerrick/2839458 to your computer and use it in GitHub Desktop.
Override how rails computes asset tags to work in multi-server deployments via git commits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Override how rails computes asset tags to work in multi-server deployments via git commits | |
module ActionView | |
module Helpers | |
module AssetTagHelper | |
def rails_asset_id(source) | |
if asset_id = ENV["RAILS_ASSET_ID"] | |
asset_id | |
else | |
if @@cache_asset_timestamps && (asset_id = @@asset_timestamps_cache[source]) | |
asset_id | |
else | |
path = File.join(ASSETS_DIR, source) | |
asset_id = File.exist?(path) ? `git log --format="%H" --max-count=1 #{path}`[0..12] : '' | |
if @@cache_asset_timestamps | |
@@asset_timestamps_cache_guard.synchronize do | |
@@asset_timestamps_cache[source] = asset_id | |
end | |
end | |
asset_id | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment