asset_id 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/asset_id.rb +12 -8
- metadata +1 -1
data/lib/asset_id.rb
CHANGED
@@ -23,7 +23,11 @@ module AssetID
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.absolute_path(path)
|
26
|
-
File.join
|
26
|
+
path =~ /#{path_prefix}/ ? path : File.join(path_prefix, path)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.relative_path(path)
|
30
|
+
path.gsub(path_prefix, '')
|
27
31
|
end
|
28
32
|
|
29
33
|
def self.assets
|
@@ -37,9 +41,9 @@ module AssetID
|
|
37
41
|
end
|
38
42
|
|
39
43
|
def self.fingerprint(path)
|
40
|
-
path =
|
44
|
+
path = absolute_path(path)
|
41
45
|
d = Digest::MD5.hexdigest(File.read(path))
|
42
|
-
path = path
|
46
|
+
path = relative_path(path)
|
43
47
|
File.join File.dirname(path), "#{File.basename(path, File.extname(path))}-id-#{d}#{File.extname(path)}"
|
44
48
|
end
|
45
49
|
|
@@ -110,7 +114,7 @@ module AssetID
|
|
110
114
|
assets.each do |asset|
|
111
115
|
fp = fingerprint(asset)
|
112
116
|
|
113
|
-
puts "asset_id: Uploading #{asset} as #{fp}" if options[:debug]
|
117
|
+
puts "asset_id: Uploading #{relative_path(asset)} as #{fp}" if options[:debug]
|
114
118
|
|
115
119
|
mime_type = MIME::Types.of(asset).first.to_s
|
116
120
|
|
@@ -128,8 +132,8 @@ module AssetID
|
|
128
132
|
|
129
133
|
puts "asset_id: headers: #{headers.inspect}" if options[:debug]
|
130
134
|
|
131
|
-
if options[:cache] and cache[asset] and cache[asset][:fingerprint] == fp
|
132
|
-
puts "asset_id: Cache hit #{asset} - doing nothing"
|
135
|
+
if options[:cache] and cache[relative_path(asset)] and cache[relative_path(asset)][:fingerprint] == fp
|
136
|
+
puts "asset_id: Cache hit #{relative_path(asset)} - doing nothing" if options[:debug]
|
133
137
|
else
|
134
138
|
AWS::S3::S3Object.store(
|
135
139
|
fp,
|
@@ -139,11 +143,11 @@ module AssetID
|
|
139
143
|
) unless options[:dry_run]
|
140
144
|
end
|
141
145
|
|
142
|
-
cache[asset] = {:expires => expiry_date.to_s, :fingerprint => fp}
|
146
|
+
cache[relative_path(asset)] = {:expires => expiry_date.to_s, :fingerprint => fp}
|
143
147
|
end
|
144
148
|
|
145
149
|
puts "cache:\n#{YAML.dump(cache)}" if options[:debug]
|
146
|
-
File.open(cache_path, 'w') {|f| f.write(YAML.dump(cache))}
|
150
|
+
File.open(cache_path, 'w') {|f| f.write(YAML.dump(cache))} if options[:cache] and !options[:dry_run]
|
147
151
|
end
|
148
152
|
|
149
153
|
end
|