Class: Stickler::Repository::Remote

Inherits:
Object
  • Object
show all
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.

Direct Known Subclasses

RemoteMirror

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo_uri, options = {}) ⇒ Remote

Returns a new instance of Remote.



17
18
19
20
21
# File 'lib/stickler/repository/remote.rb', line 17

def initialize( repo_uri, options = {}   )
  @uri           = Addressable::URI.parse( ensure_http( ensure_trailing_slash( repo_uri ) ) )
  @authenticator = load_authenticator( @uri )
  @specs_list    = nil
end

Instance Attribute Details

#authenticatorObject (readonly)

Returns the value of attribute authenticator.



15
16
17
# File 'lib/stickler/repository/remote.rb', line 15

def authenticator
  @authenticator
end

Instance Method Details

#delete(spec) ⇒ Object

See Api#delete



121
122
123
124
125
126
127
# File 'lib/stickler/repository/remote.rb', line 121

def delete( spec )
  return false unless remote_gem_file_exist?( spec )
  resource_request( gem_resource( spec ), :method => :delete )
  return true
rescue Excon::Errors::Error
  return false
end

#gems_uriObject

See Api#gems_uri



32
33
34
# File 'lib/stickler/repository/remote.rb', line 32

def gems_uri
  @gems_uri ||= self.uri.join( "gems/" )
end

#get(spec) ⇒ Object

See Api#get



73
74
75
76
# File 'lib/stickler/repository/remote.rb', line 73

def get( spec )
  return download_gem( spec ) if remote_gem_file_exist?( spec )
  return nil
end

#latest_specs_listObject

The array of latests specs from usptream



54
55
56
# File 'lib/stickler/repository/remote.rb', line 54

def latest_specs_list
  Marshal.load( download_latest_specs_list )
end

#open(spec, &block) ⇒ Object

See Api#open



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/stickler/repository/remote.rb', line 132

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



81
82
83
84
85
86
87
88
89
# File 'lib/stickler/repository/remote.rb', line 81

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 )
  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



61
62
63
64
65
66
67
68
# File 'lib/stickler/repository/remote.rb', line 61

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_listObject

The array of specs from upstream



47
48
49
# File 'lib/stickler/repository/remote.rb', line 47

def specs_list
  Marshal.load( download_specs_list )
end

#unyank(spec) ⇒ Object

See Api#unyank



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/stickler/repository/remote.rb', line 106

def unyank( spec )
  if remote_gem_file_exist?( spec ) && search_for( spec ).empty? then
    query = { :spec_name => spec.name, :version => spec.version.to_s, :platform => spec.platform.to_s }
    resource_request( unyank_resource, :query => query  )
    return true
  else
    return nil
  end
rescue Excon::Errors::Error => e
  raise Stickler::Repository::Error, "Failure unyanking: #{e.inspect}"
end

#uriObject

See Api#uri



25
26
27
# File 'lib/stickler/repository/remote.rb', line 25

def uri
  @uri
end

#uri_for_gem(spec) ⇒ Object

See Api#uri_from_gem



39
40
41
42
# File 'lib/stickler/repository/remote.rb', line 39

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



94
95
96
97
98
99
100
101
# File 'lib/stickler/repository/remote.rb', line 94

def yank( spec )
  return nil unless remote_gem_file_exist?( spec )
  query = { :gem_name => spec.name, :version => spec.version.to_s, :platform => spec.platform.to_s }
  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