class Spandx::Rubygems::Backups

Attributes

base_url[R]

Public Class Methods

new(base_url: 'https://s3-us-west-2.amazonaws.com/rubygems-dumps/') click to toggle source
# File lib/spandx/rubygems/backups.rb, line 8
def initialize(base_url: 'https://s3-us-west-2.amazonaws.com/rubygems-dumps/')
  @base_url = base_url
  @http = Net::Hippie::Client.new
end

Public Instance Methods

each() { |backup(join, db_connection)| ... } click to toggle source
# File lib/spandx/rubygems/backups.rb, line 13
def each
  response = @http.get(base_url)
  to_xml(response.body).search('//Contents/Key').reverse.each do |node|
    next unless valid?(node.text)

    yield Backup.new(URI.join(base_url, node.text), db_connection)
  end
end

Private Instance Methods

db_connection() click to toggle source
# File lib/spandx/rubygems/backups.rb, line 33
def db_connection
  @db_connection ||=
    begin
      require 'pg'
      PG.connect(host: File.expand_path('tmp/sockets'), dbname: 'postgres')
    end
end
to_xml(raw_xml) click to toggle source
# File lib/spandx/rubygems/backups.rb, line 24
def to_xml(raw_xml)
  Nokogiri::XML(raw_xml).tap(&:remove_namespaces!)
end
valid?(text) click to toggle source
# File lib/spandx/rubygems/backups.rb, line 28
def valid?(text)
  text.end_with?('public_postgresql.tar') &&
    text.start_with?('production')
end