Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
move indexer to its own class, kill vault
- Loading branch information
Showing
17 changed files
with
141 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
class Indexer | ||
def perform | ||
log "Updating the index" | ||
update_index | ||
log "Finished updating the index" | ||
end | ||
|
||
def write_gem(body, spec) | ||
gem_file = directory.files.create( | ||
:body => body.string, | ||
:key => "gems/#{spec.original_name}.gem", | ||
:public => true | ||
) | ||
|
||
self.class.indexer.abbreviate spec | ||
self.class.indexer.sanitize spec | ||
|
||
gem_spec = directory.files.create( | ||
:body => Gem.deflate(Marshal.dump(spec)), | ||
:key => "quick/Marshal.4.8/#{spec.original_name}.gemspec.rz", | ||
:public => true | ||
) | ||
end | ||
|
||
def directory | ||
fog.directories.get($rubygems_config[:s3_bucket]) | ||
end | ||
|
||
private | ||
|
||
def fog | ||
$fog || Fog::Storage.new( | ||
:provider => 'Local', | ||
:local_root => Pusher.server_path('gems') | ||
) | ||
end | ||
|
||
def stringify(value) | ||
final = StringIO.new | ||
gzip = Zlib::GzipWriter.new(final) | ||
gzip.write(Marshal.dump(value)) | ||
gzip.close | ||
|
||
final.string | ||
end | ||
|
||
def upload(key, value) | ||
file = directory.files.create( | ||
:body => stringify(value), | ||
:key => key, | ||
:public => true | ||
) | ||
end | ||
|
||
def update_index | ||
upload("specs.4.8.gz", specs_index) | ||
log "Uploaded all specs index" | ||
upload("latest_specs.4.8.gz", latest_index) | ||
log "Uploaded latest specs index" | ||
upload("prerelease_specs.4.8.gz", prerelease_index) | ||
log "Uploaded prerelease specs index" | ||
end | ||
|
||
def minimize_specs(data) | ||
names = Hash.new { |h,k| h[k] = k } | ||
versions = Hash.new { |h,k| h[k] = Gem::Version.new(k) } | ||
platforms = Hash.new { |h,k| h[k] = k } | ||
|
||
data.each do |row| | ||
row[0] = names[row[0]] | ||
row[1] = versions[row[1].strip] | ||
row[2] = platforms[row[2]] | ||
end | ||
|
||
data | ||
end | ||
|
||
def specs_index | ||
minimize_specs Version.rows_for_index | ||
end | ||
|
||
def latest_index | ||
minimize_specs Version.rows_for_latest_index | ||
end | ||
|
||
def prerelease_index | ||
minimize_specs Version.rows_for_prerelease_index | ||
end | ||
|
||
def log(message) | ||
Rails.logger.info "[GEMCUTTER:#{Time.now}] #{message}" | ||
end | ||
|
||
def self.indexer | ||
@indexer ||= | ||
begin | ||
indexer = Gem::Indexer.new(Pusher.server_path, :build_legacy => false) | ||
def indexer.say(message) end | ||
indexer | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.