Created
April 20, 2012 13:18
-
-
Save gmontard/2428488 to your computer and use it in GitHub Desktop.
Sync asset cached file to Windows Azure using waz-sync gem
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
##### | |
## Add this line to your environment.rb file | |
# require 'lib/override_assetfile_cache.rb' | |
#### | |
module ActionView | |
module Helpers | |
module AssetTagHelper | |
def write_asset_file_contents(joined_asset_path, asset_paths) | |
FileUtils.mkdir_p(File.dirname(joined_asset_path)) | |
File.open(joined_asset_path, "w+") { |cache| cache.write(join_asset_file_contents(asset_paths)) } | |
# Set mtime to the latest of the combined files to allow for | |
# consistent ETag without a shared filesystem. | |
mt = asset_paths.map { |p| File.mtime(asset_file_path(p)) }.max | |
File.utime(mt, mt, joined_asset_path) | |
###################### | |
### Azure CDN Sync ### | |
###################### | |
begin | |
azure = WazSync.new() | |
folder = joined_asset_path.match(/^.*public\/([^\/]*)\/(.*)$/)[1] | |
filename = joined_asset_path.match(/^.*public\/([^\/]*)\/(.*)$/)[2] | |
container = azure.find_or_create_container(folder) | |
azure.send_or_update(container, joined_asset_path, filename) | |
rescue | |
logger.info("Azure Sync Failed") | |
end | |
###################### | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment