module Polisher::GemRetriever::ClassMethods

Public Instance Methods

client() click to toggle source

Return handler to internal curl helper

# File lib/polisher/gem/retriever.rb, line 16
def client
  require 'curb'

  @client ||= Curl::Easy.new
end
download_gem(name, version) click to toggle source

Download the specified gem and return the binary file contents as a string

@return [String] binary gem contents

# File lib/polisher/gem/retriever.rb, line 25
def download_gem(name, version)
  cached = GemCache.get(name, version)
  return cached unless cached.nil?

  client.url = "https://rubygems.org/gems/#{name}-#{version}.gem"
  client.follow_location = true
  client.http_get
  gemf = client.body_str

  GemCache.set(name, version, gemf)
  gemf
end
downloaded_gem_path(name, version) click to toggle source

Returns path to downloaded gem

@return [String] path to downloaded gem

# File lib/polisher/gem/retriever.rb, line 48
def downloaded_gem_path(name, version)
  # ensure gem is downloaded
  download_gem name, version
  GemCache.path_for(name, version)
end
earliest_matching(dep) click to toggle source

Retrieve earliest version of gem matching dep

# File lib/polisher/gem/retriever.rb, line 94
def earliest_matching(dep)
  version = earliest_version_matching(dep)
  raise RuntimeError, "no version found" if version.nil?
  retrieve dep.name, version
end
from_rubygems(name, version) click to toggle source

Download the specified gem / version from rubygems and return instance of Polisher::Gem class corresponding to it

# File lib/polisher/gem/retriever.rb, line 40
def from_rubygems(name, version)
  download_gem name, version
  from_gem downloaded_gem_path(name, version)
end
latest_in_target(name, target) click to toggle source

Retrieve latest version of gem in target

# File lib/polisher/gem/retriever.rb, line 120
def latest_in_target(name, target)
  version = latest_version_in_target(name, target)
  raise RuntimeError, "no matching version" if version.nil?
  retrieve name, version
end
latest_matching(dep) click to toggle source

Retrieve latest version of gem matching dep

# File lib/polisher/gem/retriever.rb, line 87
def latest_matching(dep)
  version = latest_version_matching(dep)
  raise RuntimeError, "no version found" if version.nil?
  retrieve dep.name, version
end
matching(dep, specifier) click to toggle source

Retrieve version of gem matching dep and specifier

# File lib/polisher/gem/retriever.rb, line 108
def matching(dep, specifier)
  case specifier
  when LATEST_SPECIFIER
    latest_matching(dep)
  when EARLIEST_SPECIFIER
    earliest_matching(dep)
  else
    matching_target(dep, specifier)
  end
end
matching_target(dep, target) click to toggle source

Retrieve gem version matching target

# File lib/polisher/gem/retriever.rb, line 101
def matching_target(dep, target)
  version = version_matching_target(dep, target)
  raise RuntimeError, "no matching version" if version.nil?
  retrieve dep.name, version
end
retrieve(name, version=nil) click to toggle source

Retrieve gem metadata and contents from rubygems.org

@param [String] name string name of gem to retrieve @param [String] version string version of gem to retrieve,

optional if not specified latest version will be retrieved

@return [Polisher::Gem] representation of gem

# File lib/polisher/gem/retriever.rb, line 82
def retrieve(name, version=nil)
  version.nil? ? retrieve_latest(name) : retrieve_version(name, version)
end
retrieve_latest(name) click to toggle source

Retrieve latest gem metadata and contents from rubygems.org

@param [String] name string name of gem to retrieve @return [Polisher::Gem] representation of gem

# File lib/polisher/gem/retriever.rb, line 58
def retrieve_latest(name)
  client.url = "https://rubygems.org/api/v1/gems/#{name}.json"
  client.http_get
  spec = client.body_str
  gem  = parse spec
  gem
end
retrieve_version(name, version) click to toggle source

Retrieve specified metadata and contents for gem version from rubygems.org

@param [String] name string name of gem to retrieve @param [String] version string version of gem to retrieve @return [Polisher::Gem] representation of gem

# File lib/polisher/gem/retriever.rb, line 71
def retrieve_version(name, version)
  path = downloaded_gem_path name, version
  parse :gem => path
end