nix 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -48,38 +48,45 @@ class Gem::Specification
48
48
  desc
49
49
  end
50
50
 
51
- def nix_hash
52
- src = "http://rubygems.org/downloads/#{full_name}.gem"
53
- cashfile="#{ENV['HOME']}/.nix-ruby-gems-cache"
54
- cash = {}
55
- if FileTest.exists?(cashfile)
56
- File.open(cashfile,'r') do |f| Marshal.load(f) end
51
+ def src_url
52
+ "http://production.cf.rubygems.org/gems/#{full_name}.gem"
53
+ end
54
+
55
+ @@sha256_cache = {} unless self.class_variable_defined?(:@@sha256_cache)
56
+ def sha256
57
+ cache_file = "#{ENV['HOME']}/.gem/nix-sha256.cache"
58
+ if @@sha256_cache.empty?
59
+ if FileTest.exists?(cache_file)
60
+ File.open(cache_file,'r') do |f|
61
+ @@sha256_cache = Marshal.load(f)
62
+ end
63
+ end
57
64
  end
58
65
 
59
- if cash[src].nil? then
66
+ unless @@sha256_cache.key?(src_url)
60
67
  tmp="/tmp/ruby-gems-nix-tmp-file"
61
- system("nix-prefetch-url #{src.gsub(/([:= `$;])/,'\\\\\1')} > #{tmp} 2>/dev/null")
68
+ system("nix-prefetch-url #{src_url.gsub(/([:= `$;])/,'\\\\\1')} > #{tmp} 2>/dev/null")
62
69
  if $? == 0
63
70
  file = File.new(tmp)
64
- hash = file.readlines().first().split("\n")[0] # remove trailing \n
71
+ hash = file.readlines().first().chomp
65
72
  file.close()
66
73
  File.delete(tmp)
67
- cash[src] = hash
74
+ @@sha256_cache[src_url] = hash
68
75
  else
69
- cash[src] = "no hash"
76
+ @@sha256_cache[src_url] = "no hash"
70
77
  end
71
78
 
72
- File.open(cashfile, "w+") do |f| Marshal.dump(cash, f) end
79
+ File.open(cache_file, "w+") do |f| Marshal.dump(@@sha256_cache, f) end
73
80
  end
74
81
 
75
- return cash[src]
82
+ return @@sha256_cache[src_url]
76
83
  end
77
84
 
78
85
  def nix_derivation
79
86
  {
80
87
  :name => full_name,
81
88
  :basename => nix_name(:short),
82
- :sha256 => nix_hash,
89
+ :sha256 => sha256,
83
90
  :meta => nix_meta
84
91
  }
85
92
  end
@@ -1,3 +1,3 @@
1
1
  module Nix
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nix
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Yury G. Kudryashov
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-16 00:00:00 +03:00
18
+ date: 2011-01-17 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies: []
21
21