Class: Gem::Commands::MigrateCommand
- Inherits:
-
AbstractCommand
- Object
- AbstractCommand
- Gem::Commands::MigrateCommand
- Defined in:
- lib/commands/migrate.rb
Instance Attribute Summary collapse
-
#rubygem ⇒ Object
readonly
Returns the value of attribute rubygem.
Instance Method Summary collapse
- #check_for_approved ⇒ Object
- #description ⇒ Object
- #execute ⇒ Object
- #find(name) ⇒ Object
- #get_token ⇒ Object
-
#initialize ⇒ MigrateCommand
constructor
A new instance of MigrateCommand.
- #migrate ⇒ Object
- #upload_token(token) ⇒ Object
Constructor Details
#initialize ⇒ MigrateCommand
Returns a new instance of MigrateCommand.
8 9 10 |
# File 'lib/commands/migrate.rb', line 8 def initialize super 'migrate', description end |
Instance Attribute Details
#rubygem ⇒ Object (readonly)
Returns the value of attribute rubygem.
2 3 4 |
# File 'lib/commands/migrate.rb', line 2 def rubygem @rubygem end |
Instance Method Details
#check_for_approved ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/commands/migrate.rb', line 84 def check_for_approved say "Asking Gemcutter to verify the upload..." response = make_request(:put, "gems/#{rubygem["name"]}/migrate") do |request| request.add_field("Content-Length", 0) request.add_field("Authorization", api_key) end say response.body end |
#description ⇒ Object
4 5 6 |
# File 'lib/commands/migrate.rb', line 4 def description 'Migrate a gem your own from Rubyforge to Gemcutter.' end |
#execute ⇒ Object
12 13 14 15 |
# File 'lib/commands/migrate.rb', line 12 def execute setup migrate end |
#find(name) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/commands/migrate.rb', line 24 def find(name) require 'json' response = make_request(:get, "gems/#{name}.json") case response when Net::HTTPSuccess begin @rubygem = JSON.parse(response.body) rescue JSON::ParserError => json_error say "There was a problem parsing the data: #{json_error}" terminate_interaction end else say "This gem is currently not hosted on Gemcutter." terminate_interaction end end |
#get_token ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/commands/migrate.rb', line 43 def get_token say "Starting migration of #{rubygem["name"]} from RubyForge..." response = make_request(:post, "gems/#{rubygem["name"]}/migrate") do |request| request.add_field("Content-Length", 0) request.add_field("Authorization", api_key) end case response when Net::HTTPSuccess say "A migration token has been created." response.body else say response.body terminate_interaction end end |
#migrate ⇒ Object
17 18 19 20 21 22 |
# File 'lib/commands/migrate.rb', line 17 def migrate find(get_one_gem_name) token = get_token upload_token(token) check_for_approved end |
#upload_token(token) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/commands/migrate.rb', line 61 def upload_token(token) require 'tempfile' require 'net/scp' url = "#{self.rubygem['rubyforge_project']}.rubyforge.org" say "Uploading the migration token to #{url}. Please enter your RubyForge login:" login = ask("Login: ") password = ask_for_password("Password: ") begin Net::SCP.start(url, login, :password => password) do |scp| temp_token = Tempfile.new("token") temp_token.chmod 0644 temp_token.write(token) temp_token.close scp.upload! temp_token.path, "/var/www/gforge-projects/#{rubygem['rubyforge_project']}/migrate-#{rubygem['name']}.html" end say "Successfully uploaded your token." rescue Exception => e say "There was a problem uploading your token: #{e}" end end |