Class: Gfid::Gem

Inherits:
Object
  • Object
show all
Defined in:
lib/gfid/gem.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = { }) ⇒ Gem

Returns a new instance of Gem.



7
8
9
10
# File 'lib/gfid/gem.rb', line 7

def initialize(name, options={ })
  @name = name
  @version = options[:version]
end

Instance Attribute Details

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



5
6
7
# File 'lib/gfid/gem.rb', line 5

def dependencies
  @dependencies
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/gfid/gem.rb', line 5

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



5
6
7
# File 'lib/gfid/gem.rb', line 5

def version
  @version
end

Instance Method Details

#ask_dependenciesObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gfid/gem.rb', line 12

def ask_dependencies
  res = Rubygems.dependencies(name)
  result = optimize_gem(res)

  result.map do |name, version|
    if name
      version = version.split(" ").last
      self.class.new(name, :version => version)
    end
  end
rescue => e
  puts "[ERROR]"
  puts "Can't take gem file"
  puts "gem_name: " + name
  puts "gem_current_version: " + version
  puts "gem_version: " + versions.inspect
  puts "[Response from Rubygems]"
  puts res.inspect
  raise StandardError
end

#download!Object



62
63
64
# File 'lib/gfid/gem.rb', line 62

def download!
  Rubygems.download(filename)
end

#filenameObject



66
67
68
# File 'lib/gfid/gem.rb', line 66

def filename
  name + "-" + version + ".gem"
end

#optimize_gem(response) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gfid/gem.rb', line 33

def optimize_gem(response)
  if version
    return response.first[:dependencies] if version == "0"
    response.select do |gem_info|
      versions.include?(gem_info[:number])
    end.first[:dependencies]
  else
    # get the newest
    @version = response.first[:number]
    response.first[:dependencies]
  end
end

#versionsObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/gfid/gem.rb', line 46

def versions
  split_version = version.split(".")
  if split_version.size == 3
    support = split_version[0..1].join(".")
    return [version,support]
  end
  if split_version.size == 2
    filling = (split_version.uniq.size == 1 && split_version.uniq.first == '0') ? '.1' : '.0'
    return [version, version+filling]
  end
  if split_version.size == 1
    filling = (split_version.uniq.size == 1 && split_version.uniq.first == '0') ? '.1' : '.0'
    return [version, version+'.0', version+'.0'+filling]
  end
end