gemstache 0.2.0

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.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2009, Nick Quaranto
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,93 @@
1
+ require 'rubygems/local_remote_options'
2
+ require 'rubygems/gemcutter_utilities'
3
+ require 'yaml'
4
+
5
+ class Gem::Commands::StacheCommand < Gem::Command
6
+ include Gem::LocalRemoteOptions
7
+ include Gem::GemcutterUtilities
8
+
9
+ def description
10
+ 'Upload a new gem to a private collection on gemstache.com.'
11
+ end
12
+
13
+ def arguments
14
+ "GEM built gem to push up"
15
+ end
16
+
17
+ def usage
18
+ "#{program_name} [GEM] [--configure]"
19
+ end
20
+
21
+ def initialize
22
+ super 'stache', description
23
+
24
+ add_option(
25
+ '--configure',
26
+ 'Configure credentials for Gemstache'
27
+ ) do |value, options|
28
+ options[:configure] = true
29
+ end
30
+ end
31
+
32
+ def execute
33
+ if options[:configure]
34
+ configure_credentials
35
+ else
36
+ get_all_gem_names.each do |gemfile|
37
+ upload_gem(gemfile)
38
+ end
39
+ end
40
+ end
41
+
42
+ def configure_credentials
43
+ say "Enter your gemstache.com credentials."
44
+
45
+ domain = ask " Domain: "
46
+ email = ask " Email: "
47
+ password = ask_for_password "Password: "
48
+ say "\n"
49
+
50
+ domain += '.gemstache.com' unless domain =~ /\.gemstache\.com/
51
+
52
+ old_host = ENV['RUBYGEMS_HOST']
53
+ ENV['RUBYGEMS_HOST'] = "https://#{domain}"
54
+ response = rubygems_api_request(:get, "api/v1/api_key") do |request|
55
+ request.basic_auth email, password
56
+ end
57
+ ENV['RUBYGEMS_HOST'] = old_host
58
+
59
+ with_response response do |resp|
60
+ say "Signed in."
61
+ config = self.class.read_gemstache_config
62
+ config[domain] = resp.body.chomp
63
+
64
+ f = File.new(self.class.gemstache_config_file, 'w')
65
+ f.write((config.to_yaml))
66
+ f.close
67
+ end
68
+ end
69
+
70
+ def upload_gem(name)
71
+ say "Pushing gem to Gemstache..."
72
+
73
+ old_host = ENV['RUBYGEMS_HOST']
74
+ ENV['RUBYGEMS_HOST'] = "http://#{self.class.read_gemstache_config['domain']}"
75
+ response = rubygems_api_request(:post, 'api/v1/gems') do |request|
76
+ request.body = Gem.read_binary name
77
+ request.add_field "Content-Length", request.body.size
78
+ request.add_field "Content-Length", request.body.size
79
+ request.add_field "Content-Type", "application/octet-stream"
80
+ end
81
+ ENV['RUBYGEMS_HOST'] = old_host
82
+
83
+ with_response response
84
+ end
85
+
86
+ def self.read_gemstache_config
87
+ File.exists?(gemstache_config_file) ? YAML.load_file(gemstache_config_file) : {}
88
+ end
89
+
90
+ def self.gemstache_config_file
91
+ File.join(Gem.user_home, '.gem', 'gemstache')
92
+ end
93
+ end
@@ -0,0 +1,30 @@
1
+ require 'rubygems/install_update_options'
2
+ require 'rubygems/remote_fetcher'
3
+ require 'rubygems/commands/stache_command'
4
+
5
+ class Gem::RemoteFetcher
6
+ alias_method :existing_request, :request
7
+ def request(uri, request_class, last_modified = nil)
8
+ existing_request(uri, request_class, last_modified = nil) do |request|
9
+ yield request if block_given?
10
+
11
+ if uri.host =~ /\.gemstache\.com/
12
+ api_key = $override_api_key || Gem::Commands::StacheCommand.read_gemstache_config[uri.host]
13
+ request.add_field('Authorization', api_key) if api_key
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ module Gem::InstallUpdateOptions
20
+ alias_method :existing_add_install_update_options, :add_install_update_options
21
+
22
+ def add_install_update_options
23
+ existing_add_install_update_options
24
+
25
+ add_option(:"Install/Update", '--gemstache-api-key',
26
+ 'Specify an API key for authorization with Gemstache') do |value, options|
27
+ $override_api_key = value
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems/command_manager'
2
+ require 'rubygems/gemstache_fetcher'
3
+ Gem::CommandManager.instance.register_command :stache
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gemstache
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
+ platform: ruby
12
+ authors:
13
+ - Ken Robertson
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-13 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Adds commands for managing private gems through gemstache.com
23
+ email: ken@linkedlabs.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - LICENSE
32
+ - lib/rubygems/commands/stache_command.rb
33
+ - lib/rubygems/gemstache_fetcher.rb
34
+ - lib/rubygems_plugin.rb
35
+ has_rdoc: true
36
+ homepage: http://gemstache.com
37
+ licenses: []
38
+
39
+ post_install_message: |+
40
+
41
+ =====================================================================
42
+
43
+ Enjoy using your stache! Now you can do the following:
44
+
45
+ gem stache --configure configure your credentials
46
+ gem stache yourgem-1.0.0.gem upload the gem to your stache
47
+
48
+ =====================================================================
49
+
50
+ rdoc_options: []
51
+
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.3.7
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Adds commands to download and upload gems to gemstache.com.
79
+ test_files: []
80
+