asset_id 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/asset_id.rb +10 -23
  2. metadata +3 -3
data/lib/asset_id.rb CHANGED
@@ -21,35 +21,22 @@ module AssetID
21
21
  @@asset_paths
22
22
  end
23
23
 
24
- def self.assets
25
- a = []
26
- asset_paths.each do |asset_path|
27
- path = File.join path_prefix, asset_path
28
- next unless File.exists? path
29
- if File.directory? path
30
- a += gather_assets_for(path)
31
- else
32
- a << path
33
- end
34
- end
35
- a
24
+ def self.absolute_path(path)
25
+ File.join path_prefix, path
36
26
  end
37
27
 
38
- def self.gather_assets_for(dir)
39
- a = []
40
- Dir.glob(File.join dir, '/*').each do |file|
41
- if File.directory? file
42
- a += gather_assets_for(file)
43
- else
44
- a << file
45
- end
46
- end
47
- a
28
+ def self.assets
29
+ asset_paths.inject([]) {|assets, path|
30
+ path = absolute_path(path)
31
+ assets << path if File.exists? path and !File.directory? path
32
+ assets += Dir.glob(path+'/**/*').inject([]) {|m, file|
33
+ m << file unless File.directory? file; m
34
+ }
35
+ }
48
36
  end
49
37
 
50
38
  def self.fingerprint(path)
51
39
  path = File.join path_prefix, path unless path =~ /#{path_prefix}/
52
- #d = File.mtime(path).to_i.to_s
53
40
  d = Digest::MD5.hexdigest(File.read(path))
54
41
  path = path.gsub(path_prefix, '')
55
42
  File.join File.dirname(path), "#{File.basename(path, File.extname(path))}-id-#{d}#{File.extname(path)}"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asset_id
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Richard Taylor