class GemMirror::Source

The Source class is used for storing information about an external source such as the name and the Gems to mirror.

@!attribute [r] name

@return [String]

@!attribute [r] host

@return [String]

@!attribute [r] gems

@return [Array]

Attributes

gems[R]
host[R]
name[R]

Public Class Methods

new(name, host, gems = []) click to toggle source

@param [String] name @param [String] host @param [Array] gems

   # File lib/gem_mirror/source.rb
23 def initialize(name, host, gems = [])
24   @name = name.downcase.gsub(/\s+/, "_")
25   @host = host.chomp("/")
26   @gems = gems
27 end

Public Instance Methods

fetch_gem(name, version) click to toggle source

Fetches the `.gem` file of a given Gem and version.

@param [String] name @param [String] version @return [String]

   # File lib/gem_mirror/source.rb
69 def fetch_gem(name, version)
70   http_get(host + "/gems/#{name}-#{version}.gem").body
71 end
fetch_specification(name, version) click to toggle source

Fetches the Gem specification of a Gem.

@param [String] name @param [String] version @return [String]

   # File lib/gem_mirror/source.rb
55 def fetch_specification(name, version)
56   url = host + "/quick/#{Configuration.marshal_identifier}" \
57         "/#{name}-#{version}.gemspec.rz"
58 
59   http_get(url).body
60 end
fetch_versions() click to toggle source

Fetches a list of all the available Gems and their versions.

@return [String]

   # File lib/gem_mirror/source.rb
44 def fetch_versions
45   http_get("#{host}/#{Configuration.versions_file}").body
46 end
gem(name, requirement = nil) click to toggle source

Adds a new Gem to the source.

@param [String] name @param [String] requirement

   # File lib/gem_mirror/source.rb
79 def gem(name, requirement = nil)
80   gems << Gem.new(name, requirement)
81 end
updated(new_gems) click to toggle source

Returns a new Source instance based on the current one.

@param [Array] new_gems The gems to set, overwrites the current ones. @return [Source]

   # File lib/gem_mirror/source.rb
35 def updated(new_gems)
36   self.class.new(name, host, new_gems)
37 end

Private Instance Methods

client() click to toggle source

@return [HTTPClient]

    # File lib/gem_mirror/source.rb
102 def client
103   @client ||= HTTPClient.new
104 end
http_get(url) click to toggle source

Requests the given HTTP resource.

@param [String] url @return [HTTP::Message]

   # File lib/gem_mirror/source.rb
91 def http_get(url)
92   response = client.get(url, follow_redirect: true)
93 
94   raise HTTPClient::BadResponseError, response.reason unless HTTP::Status.successful?(response.status)
95 
96   response
97 end