Class: Source::Gem

Inherits:
Base show all
Defined in:
lib/gpm/source/gem.rb

Direct Known Subclasses

Bundler

Defined Under Namespace

Classes: Factory, FilesFromGemProvider

Constant Summary

Constants inherited from Base

Base::DEFAULTS

Instance Attribute Summary collapse

Attributes inherited from Base

#files_provider

Attributes included from HasOptionMethods

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

constant_field, #contains_file?, #file_contents, #files, #maintainer

Methods included from HasOptionMethods

included

Constructor Details

#initialize(metadata, files_provider = nil, options = {}) ⇒ Gem

Returns a new instance of Gem.



87
88
89
90
# File 'lib/gpm/source/gem.rb', line 87

def initialize(, files_provider = nil, options = {})
  @metadata = 
  super(files_provider, options)
end

Instance Attribute Details

#metadataObject (readonly)

Returns the value of attribute metadata.



86
87
88
# File 'lib/gpm/source/gem.rb', line 86

def 
  @metadata
end

Class Method Details

.read_metadata(gem_file) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/gpm/source/gem.rb', line 34

def self.(gem_file)
   = nil

  Dir.chdir(File.dirname(gem_file)) do
    if gem_file.end_with?('.gem')
      contents = nil
      File.open(gem_file, 'r') do |f|
        ::Gem::Package.open(f, 'r') do |gem|
           = gem.
        end
      end
    elsif gem_file.end_with?('.gemspec')
       = ::Gem::Specification.load(gem_file)
    else
      raise "Unknown file type of #{gem_file}. Need a .gem or .gemspec file"
    end
  end
  raise "Could not read metadata for #{gem_file.inspect}" unless 
  
end

Instance Method Details

#architectureObject



119
120
121
122
123
124
125
126
# File 'lib/gpm/source/gem.rb', line 119

def architecture
  # if the gemspec has extensions defined, then this should be a 'native' arch.
  if !.extensions.empty?
    "native"
  else
    "all"
  end
end

#dependenciesObject



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/gpm/source/gem.rb', line 128

def dependencies
  dependencies = []
  .runtime_dependencies.map do |dep|
    # rubygems 1.3.5 doesn't have 'Gem::Dependency#requirement'
    if dep.respond_to?(:requirement)
      reqs = dep.requirement.to_s.gsub(/,/, '')
    else
      reqs = dep.version_requirements
    end

    # Some reqs can be ">= a, < b" versions, let's handle that.
    reqs.to_s.split(/, */).each do |req|
      dependencies << "#{name(dep)} #{req}"
    end
  end
  return dependencies + ["libc6", "ruby"]
end

#emailObject



113
114
115
116
# File 'lib/gpm/source/gem.rb', line 113

def email
  result = .email
  return result.kind_of?(Array) ? result.first : result
end

#name(name_provider = nil) ⇒ Object



104
105
106
107
# File 'lib/gpm/source/gem.rb', line 104

def name(name_provider=nil)
  name_provider ||= 
  "rubygem-#{name_provider.name}"
end