gemcutter 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,15 @@
1
1
  class Gem::Commands::DowngradeCommand < Gem::Command
2
- DESCRIPTION = 'Return to using RubyForge as your primary gem source'
3
-
4
2
  def description
5
- DESCRIPTION
3
+ 'Return to using RubyForge as your primary gem source'
6
4
  end
7
5
 
8
6
  def initialize
9
- super 'downgrade', DESCRIPTION
7
+ super 'downgrade', description
10
8
  end
11
9
 
12
10
  def execute
13
11
  say "Your primary gem source is now gems.rubyforge.org"
14
- Gem.sources.delete "http://gemcutter.org"
15
- Gem.sources << "http://gems.rubyforge.org"
12
+ Gem.sources.delete URL
16
13
  Gem.configuration.write
17
14
  end
18
15
  end
data/lib/commands/push.rb CHANGED
@@ -2,10 +2,9 @@ require 'yaml'
2
2
  require 'net/http'
3
3
 
4
4
  class Gem::Commands::PushCommand < Gem::Command
5
- DESCRIPTION = 'Push a gem up to Gemcutter'
6
5
 
7
6
  def description
8
- DESCRIPTION
7
+ 'Push a gem up to Gemcutter'
9
8
  end
10
9
 
11
10
  def arguments
@@ -17,21 +16,20 @@ class Gem::Commands::PushCommand < Gem::Command
17
16
  end
18
17
 
19
18
  def initialize
20
- super 'push', DESCRIPTION
19
+ super 'push', description
21
20
  end
22
21
 
23
22
  def execute
24
23
  say "Pushing gem to Gemcutter..."
25
24
 
26
25
  name = get_one_gem_name
27
- config = YAML.load_file(File.expand_path("~/.gemrc"))
28
26
  site = ENV['TEST'] ? "local" : "org"
29
27
  url = URI.parse("http://gemcutter.#{site}/gems")
30
28
 
31
29
  request = Net::HTTP::Post.new(url.path)
32
30
  request.body = File.open(name).read
33
31
  request.content_length = request.body.size
34
- request.basic_auth config[:gemcutter_email], config[:gemcutter_password]
32
+ request.initialize_http_header("HTTP_AUTHORIZATION" => Gem.configuration[:gemcutter_key])
35
33
 
36
34
  response = Net::HTTP.new(url.host, url.port).start { |http| http.request(request) }
37
35
  say response.body
@@ -1,20 +1,57 @@
1
- class Gem::Commands::UpgradeCommand < Gem::Command
2
- DESCRIPTION = 'Upgrade your gem source to Gemcutter'
1
+ class Gem::StreamUI
2
+ def ask_for_password(message)
3
+ system "stty -echo"
4
+ password = ask(message)
5
+ system "stty echo"
6
+ password
7
+ end
8
+ end
3
9
 
10
+ class Gem::Commands::UpgradeCommand < Gem::Command
4
11
  def description
5
- DESCRIPTION
12
+ 'Upgrade your gem source to Gemcutter'
13
+ end
14
+
15
+ def ask_for_password(message)
16
+ ui.ask_for_password(message)
6
17
  end
7
18
 
8
19
  def initialize
9
- super 'upgrade', DESCRIPTION
20
+ super 'upgrade', description
10
21
  end
11
22
 
12
23
  def execute
13
- say "Upgrading your primary gem source to gems.gemcutter.org"
14
- Gem.sources.delete "http://gems.rubyforge.org"
15
- Gem.sources << "http://gemcutter.org"
24
+ add_source
25
+ sign_in
26
+ end
27
+
28
+ def add_source
29
+ if Gem.sources.include?(URL)
30
+ say "Gemcutter is already your primary gem source. Please use `gem downgrade` if you wish to no longer use Gemcutter."
31
+ else
32
+ say "Upgrading your primary gem source to gemcutter.org"
33
+ Gem.sources.unshift URL
34
+ Gem.configuration.write
35
+ end
36
+ end
37
+
38
+ def sign_in
39
+ say "Enter your Gemcutter credentials. Don't have an account yet? Create one at #{URL}/sign_up"
40
+
41
+ email = ask("Email: ")
42
+ password = ask_for_password("Password: ")
43
+
44
+ site = ENV['TEST'] ? "local" : "org"
45
+ url = URI.parse("http://gemcutter.#{site}/api_key")
46
+
47
+ request = Net::HTTP::Get.new(url.path)
48
+ request.basic_auth email, password
49
+ response = Net::HTTP.new(url.host, url.port).start { |http| http.request(request) }
50
+
51
+ Gem.configuration[:gemcutter_key] = response.body
16
52
  Gem.configuration.write
17
53
  end
54
+
18
55
  end
19
56
 
20
57
  Gem::CommandManager.instance.register_command :upgrade
@@ -3,3 +3,5 @@ require 'rubygems/command_manager'
3
3
  require 'commands/downgrade'
4
4
  require 'commands/push'
5
5
  require 'commands/upgrade'
6
+
7
+ URL = "http://gemcutter.org" unless defined?(URL)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemcutter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Quaranto
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-02 00:00:00 -04:00
12
+ date: 2009-06-09 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15