Class: Gem::Specification
- Inherits:
-
Object
- Object
- Gem::Specification
- Defined in:
- lib/nix/gem-nix-command.rb
Constant Summary collapse
- @@sha256_cache =
{}
Instance Method Summary collapse
- #nix_derivation ⇒ Object
- #nix_meta ⇒ Object
- #nix_name(mode = :symbol) ⇒ Object
- #sha256 ⇒ Object
- #src_url ⇒ Object
Instance Method Details
#nix_derivation ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/nix/gem-nix-command.rb', line 70 def nix_derivation { :name => full_name, :basename => nix_name(:short), :sha256 => sha256, :meta => } end |
#nix_meta ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/nix/gem-nix-command.rb', line 31 def { :homepage => homepage, :description => summary, :longDescription => description, :license => licenses }.reject { |k, v| v.nil? or (v.respond_to?(:empty?) and v.empty?) } end |
#nix_name(mode = :symbol) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/nix/gem-nix-command.rb', line 16 def nix_name(mode = :symbol) case mode when :symbol full_name.gsub(/[.-]/, '_').to_sym when :short name.gsub(/[.-]/, '_') when :short_sym nix_name(:short).to_sym when :rhs_sym ("g." + nix_name(:symbol).to_s).to_sym else raise "Unknown mode #{mode} passed to nix_name" end end |
#sha256 ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/nix/gem-nix-command.rb', line 45 def sha256 cache_file = "#{ENV['HOME']}/.gem/nix-sha256.cache" if @@sha256_cache.empty? and FileTest.exists?(cache_file) File.open(cache_file,'r') { |f| @@sha256_cache = Marshal.load(f) } end unless @@sha256_cache.key?(src_url) tmp="/tmp/ruby-gems-nix-tmp-file" system("nix-prefetch-url #{src_url.gsub(/([:= `$;])/,'\\\\\1')} > #{tmp} 2>/dev/null") if $? == 0 file = File.new(tmp) hash = file.readlines().first().chomp file.close() File.delete(tmp) @@sha256_cache[src_url] = hash else @@sha256_cache[src_url] = "no hash" end File.open(cache_file, "w+") do |f| Marshal.dump(@@sha256_cache, f) end end return @@sha256_cache[src_url] end |
#src_url ⇒ Object
40 41 42 |
# File 'lib/nix/gem-nix-command.rb', line 40 def src_url "http://production.cf.rubygems.org/gems/#{full_name}.gem" end |