Skip to content

Commit

Permalink
Add support for overwriting existing Gem.
Browse files Browse the repository at this point in the history
Added command line -o or --overwrite.  Tested with Ruby-1.9.3-p392.  Updated
readme.markdown with new options.  Revised version.  Current gems require
Gemfile to source rubygems.org via HTTPS.
  • Loading branch information
David Smith & Khalid Shaikh authored and tomlea committed Apr 9, 2013
1 parent 7103ed6 commit 6e9175f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Gemfile.lock
vendor/bundle
.rbenv-version
test/fixtures/fake_home_path/.gem/specs
.idea
35 changes: 32 additions & 3 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ The bundler dependencies API is supported out of the box.
Authentication is left up to either the web server, or the Rack stack.
For basic auth, try [Rack::Auth](http://rack.rubyforge.org/doc/Rack/Auth/Basic.html).




![screen shot](http://pics.tomlea.co.uk/bbbba6/geminabox.png)

## System Requirements

Tested on Mac OS X 10.8.2
Ruby 1.9.3-392

Tests fail on Ruby 2.0.0-p0

## Server Setup

Expand Down Expand Up @@ -51,6 +52,34 @@ Change the host to upload to:

Simples!

## Command Line Help

Usage: gem inabox GEM [options]

Options:
-c, --configure Configure GemInABox
-g, --host HOST Host to upload to.
-o, --overwrite Overwrite Gem.


Common Options:
-h, --help Get help on this command
-V, --[no-]verbose Set the verbose level of output
-q, --quiet Silence commands
--config-file FILE Use this config file instead of default
--backtrace Show stack backtrace on errors
--debug Turn on Ruby debugging


Arguments:
GEM built gem to push up

Summary:
Push a gem up to your GemInABox

Description:
Push a gem up to your GemInABox

## Licence

Fork it, mod it, choose it, use it, make it better. All under the [do what the fuck you want to + beer/pizza public license][WTFBPPL].
Expand Down
4 changes: 2 additions & 2 deletions lib/geminabox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def fixup_bundler_rubygems!
def handle_incoming_gem(gem)
prepare_data_folders
error_response(400, "Cannot process gem") unless gem.valid?
handle_replacement(gem)
handle_replacement(gem) if params[:overwrite] == "false"
write_and_index(gem)

if api_request?
Expand Down Expand Up @@ -155,7 +155,7 @@ def handle_replacement(gem)
if existing_file_digest != gem.hexdigest
error_response(409, "Updating an existing gem is not permitted.\nYou should either delete the existing version, or change your version number.")
else
error_response(200, "Ignoring upload, you uploaded the same thing previously.")
error_response(200, "Ignoring upload, you uploaded the same thing previously.\nPlease use -o to ovewrite.")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/geminabox/version.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GeminaboxVersion = '0.10.1' unless defined? GeminaboxVersion
GeminaboxVersion = '0.10.2' unless defined? GeminaboxVersion
4 changes: 2 additions & 2 deletions lib/geminabox_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def url_for(path)
url + path.to_s
end

def push(gemfile)
response = http_client.post(url_for(:upload), {'file' => File.open(gemfile, "rb")}, {'Accept' => 'text/plain'})
def push(gemfile, options = {})
response = http_client.post(url_for(:upload), { 'file' => File.open(gemfile, "rb"), 'overwrite' => !!options[:overwrite] }, { 'Accept' => 'text/plain' })

if response.status < 300
response.body
Expand Down
6 changes: 5 additions & 1 deletion lib/rubygems/commands/inabox_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def initialize
add_option('-g', '--host HOST', "Host to upload to.") do |value, options|
options[:host] = value
end

add_option('-o', '--overwrite', "Overwrite Gem.") do |value, options|
options[:overwrite] = true
end
end

def last_minute_requires!
Expand Down Expand Up @@ -51,7 +55,7 @@ def send_gems(gemfiles)
gemfiles.each do |gemfile|
say "Pushing #{File.basename(gemfile)} to #{client.url}..."
begin
say client.push(gemfile)
say client.push(gemfile, options)
rescue GeminaboxClient::Error => e
alert_error e.message
terminate_interaction(1)
Expand Down

0 comments on commit 6e9175f

Please sign in to comment.