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
Public Class Methods
@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
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
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
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
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
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
@return [HTTPClient]
# File lib/gem_mirror/source.rb 102 def client 103 @client ||= HTTPClient.new 104 end
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