Class: Gem::Specification

Inherits:
Object
  • Object
show all
Defined in:
lib/nix/gem-nix-command.rb

Instance Method Summary collapse

Instance Method Details

#nix_derivationObject



78
79
80
81
82
83
84
85
# File 'lib/nix/gem-nix-command.rb', line 78

def nix_derivation
  {
    :name => full_name,
    :basename => nix_name(:short),
    :sha256 => nix_hash,
    :meta => nix_meta
  }
end

#nix_description(long) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/nix/gem-nix-command.rb', line 40

def nix_description(long)
  return nil if description.nil? or description.empty?
  desc = description.dup
  if not long then
    desc.sub!(/\A[[:space:]]*([^.\n]*[^.\n[:space:]]).*\z/,'\1')
    desc.sub!(/ +/, ' ')
    desc.sub!(/(.{120}).+/, '\1[...]') # Trim to 120 chars
  end
  desc
end

#nix_hashObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/nix/gem-nix-command.rb', line 51

def nix_hash
  src = "http://rubygems.org/downloads/#{full_name}.gem"
  cashfile="#{ENV['HOME']}/.nix-ruby-gems-cache"
  cash = {}
  if FileTest.exists?(cashfile)
    File.open(cashfile,'r') do |f| Marshal.load(f) end
  end

  if cash[src].nil? then
    tmp="/tmp/ruby-gems-nix-tmp-file"
    system("nix-prefetch-url #{src.gsub(/([:= `$;])/,'\\\\\1')} > #{tmp} 2>/dev/null")
    if $? == 0
      file = File.new(tmp)
      hash = file.readlines().first().split("\n")[0] # remove trailing \n
      file.close()
      File.delete(tmp)
      cash[src] = hash
    else
      cash[src] = "no hash"
    end

    File.open(cashfile, "w+") do |f| Marshal.dump(cash, f) end
  end

  return cash[src]
end

#nix_metaObject



31
32
33
34
35
36
37
38
# File 'lib/nix/gem-nix-command.rb', line 31

def nix_meta
  {
    :homepage => homepage,
    :description => nix_description(false),
    :longDescription => nix_description(true),
    :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