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
-
#http ⇒ Object
readonly
the http client.
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.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/stickler/repository/remote.rb', line 17 def initialize( repo_uri, = {} ) [:authenticator] ||= Stickler::Repository::RubygemsAuthenticator.new [:cache_manager] ||= Resourceful::InMemoryCacheManager.new if .delete(:debug) then [:logger] ||= Resourceful::StdOutLogger.new end @uri = Addressable::URI.parse( ensure_http( ensure_trailing_slash( repo_uri ) ) ) @http = Resourceful::HttpAccessor.new( ) @specs_list = nil end |
Instance Attribute Details
#http ⇒ Object (readonly)
the http client
15 16 17 |
# File 'lib/stickler/repository/remote.rb', line 15 def http @http end |
Instance Method Details
#delete(spec) ⇒ Object
See Api#delete
111 112 113 114 115 116 117 118 119 |
# File 'lib/stickler/repository/remote.rb', line 111 def delete( spec ) return false unless remote_gem_file_exist?( spec ) begin gem_resource( spec ).delete return true rescue Resourceful::UnsuccessfulHttpRequestError => e return false end end |
#gems_uri ⇒ Object
See Api#gems_uri
38 39 40 |
# File 'lib/stickler/repository/remote.rb', line 38 def gems_uri @gems_uri ||= self.uri.join( "gems/" ) end |
#get(spec) ⇒ Object
See Api#get
72 73 74 75 |
# File 'lib/stickler/repository/remote.rb', line 72 def get( spec ) return download_gem( spec ) if remote_gem_file_exist?( spec ) return nil end |
#open(spec, &block) ⇒ Object
See Api#open
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/stickler/repository/remote.rb', line 124 def open( spec, &block ) return nil unless remote_gem_file_exist?( spec ) begin 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 rescue Resourceful::UnsuccessfulHttpRequestError => e return nil end nil end |
#push(path) ⇒ Object
See Api#push
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/stickler/repository/remote.rb', line 80 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 ) begin resp = push_resource.post( IO.read( path ) ) rescue Resourceful::UnsuccessfulHttpRequestError => e msg = "Failure pushing #{path} to remote repository : response code => #{e.http_response.code}, response message => '#{e.http_response.body}'" raise Stickler::Repository::Error, msg end return spec end |
#search_for(spec) ⇒ Object
See Api#search_for
60 61 62 63 64 65 66 67 |
# File 'lib/stickler/repository/remote.rb', line 60 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
53 54 55 |
# File 'lib/stickler/repository/remote.rb', line 53 def specs_list Marshal.load( download_specs_list ) end |
#uri ⇒ Object
See Api#uri
31 32 33 |
# File 'lib/stickler/repository/remote.rb', line 31 def uri @uri end |
#uri_for_gem(spec) ⇒ Object
See Api#uri_from_gem
45 46 47 48 |
# File 'lib/stickler/repository/remote.rb', line 45 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
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/stickler/repository/remote.rb', line 95 def yank( spec ) return nil unless remote_gem_file_exist?( spec ) begin form_data = Resourceful::UrlencodedFormData.new form_data.add( "gem_name", spec.name ) form_data.add( "version", spec.version.to_s ) yank_resource.request( :delete, form_data.read, {'Content-Type' => form_data.content_type } ) return full_uri_to_gem( spec ) rescue Resourceful::UnsuccessfulHttpRequestError => e raise Stickler::Repository::Error, "Failure yanking: #{e.inspect}" end end |