asset_id 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/asset_id.rb +12 -8
  2. 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 path_prefix, path
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 = File.join path_prefix, path unless path =~ /#{path_prefix}/
44
+ path = absolute_path(path)
41
45
  d = Digest::MD5.hexdigest(File.read(path))
42
- path = path.gsub(path_prefix, '')
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))} unless options[:dry_run]
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
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: asset_id
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.4
5
+ version: 0.1.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Richard Taylor