Class: Stickler::Repository::Remote
- Inherits:
-
Object
- Object
- Stickler::Repository::Remote
- Defined in:
- lib/stickler/repository/remote.rb
Overview
A Repository::Api implementation that retrieves all is data from an HTTP based remote location. It utilizes the Modern gem server api and the gem cutter api (push/yank/unyank). The legacy gem server api is not utilized.
Instance Attribute Summary collapse
-
#authenticator ⇒ Object
readonly
Returns the value of attribute authenticator.
Instance Method Summary collapse
-
#delete(spec) ⇒ Object
See Api#delete.
-
#gems_uri ⇒ Object
See Api#gems_uri.
-
#get(spec) ⇒ Object
See Api#get.
-
#initialize(repo_uri, options = {}) ⇒ Remote
constructor
A new instance of Remote.
-
#open(spec, &block) ⇒ Object
See Api#open.
-
#push(path) ⇒ Object
See Api#push.
-
#search_for(spec) ⇒ Object
See Api#search_for.
-
#specs_list ⇒ Object
The array of specs from upstream.
-
#uri ⇒ Object
See Api#uri.
-
#uri_for_gem(spec) ⇒ Object
See Api#uri_from_gem.
-
#yank(spec) ⇒ Object
See Api#yank.
Constructor Details
#initialize(repo_uri, options = {}) ⇒ Remote
Returns a new instance of Remote.
18 19 20 21 22 |
# File 'lib/stickler/repository/remote.rb', line 18 def initialize( repo_uri, = {} ) @authenticator = [:authenticator] || Stickler::Repository::RubygemsAuthenticator.new @uri = Addressable::URI.parse( ensure_http( ensure_trailing_slash( repo_uri ) ) ) @specs_list = nil end |
Instance Attribute Details
#authenticator ⇒ Object (readonly)
Returns the value of attribute authenticator.
16 17 18 |
# File 'lib/stickler/repository/remote.rb', line 16 def authenticator @authenticator end |
Instance Method Details
#delete(spec) ⇒ Object
See Api#delete
100 101 102 103 104 105 106 |
# File 'lib/stickler/repository/remote.rb', line 100 def delete( spec ) return false unless remote_gem_file_exist?( spec ) resource_request( gem_resource( spec ), :method => :delete ) return true rescue Excon::Errors::Error => e return false end |
#gems_uri ⇒ Object
See Api#gems_uri
33 34 35 |
# File 'lib/stickler/repository/remote.rb', line 33 def gems_uri @gems_uri ||= self.uri.join( "gems/" ) end |
#get(spec) ⇒ Object
See Api#get
67 68 69 70 |
# File 'lib/stickler/repository/remote.rb', line 67 def get( spec ) return download_gem( spec ) if remote_gem_file_exist?( spec ) return nil end |
#open(spec, &block) ⇒ Object
See Api#open
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/stickler/repository/remote.rb', line 111 def open( spec, &block ) return nil unless remote_gem_file_exist?( spec ) data = download_resource( gem_resource( spec ) ) io = StringIO.new( data , "rb" ) if block_given? then begin yield io ensure io.close end else return io end nil rescue Excon::Errors::Error => e $stderr.puts e.inspect return nil end |
#push(path) ⇒ Object
See Api#push
75 76 77 78 79 80 81 82 83 |
# File 'lib/stickler/repository/remote.rb', line 75 def push( path ) spec = speclite_from_gem_file( path ) raise Stickler::Repository::Error, "gem #{spec.full_name} already exists in remote repository" if remote_gem_file_exist?( spec ) resp = resource_request( push_resource, :body => IO.read( path ) ) return spec rescue Excon::Errors::Error => e msg = "Failure pushing #{path} to remote repository : response code => #{e.response.status}, response message => '#{e.response.body}'" raise Stickler::Repository::Error, msg end |
#search_for(spec) ⇒ Object
See Api#search_for
55 56 57 58 59 60 61 62 |
# File 'lib/stickler/repository/remote.rb', line 55 def search_for( spec ) found = [] specs_list.each do |name, version, platform| up_spec = Stickler::SpecLite.new( name, version, platform ) found << up_spec if spec =~ up_spec end return found end |
#specs_list ⇒ Object
The array of specs from upstream
48 49 50 |
# File 'lib/stickler/repository/remote.rb', line 48 def specs_list Marshal.load( download_specs_list ) end |
#uri ⇒ Object
See Api#uri
26 27 28 |
# File 'lib/stickler/repository/remote.rb', line 26 def uri @uri end |
#uri_for_gem(spec) ⇒ Object
See Api#uri_from_gem
40 41 42 43 |
# File 'lib/stickler/repository/remote.rb', line 40 def uri_for_gem( spec ) return nil unless remote_gem_file_exist?( spec ) return self.gems_uri.join( spec.file_name ) end |
#yank(spec) ⇒ Object
See Api#yank
88 89 90 91 92 93 94 95 |
# File 'lib/stickler/repository/remote.rb', line 88 def yank( spec ) return nil unless remote_gem_file_exist?( spec ) query = { :gem_name => spec.name, :version => spec.version.to_s } resp = resource_request( yank_resource, :query => query ) return full_uri_to_gem( spec ) rescue Excon::Errors::Error => e raise Stickler::Repository::Error, "Failure yanking: #{e.inspect}" end |