gemrepo 0.1.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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jari Bakken
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,28 @@
1
+ = gemrepo
2
+
3
+ A simple gem server that supports push / install. Useful for hosting internal gems.
4
+
5
+ = Example
6
+
7
+ $ gemrepo --directory ~/.gemrepo --port 1234 &
8
+ $ RUBYGEMS_HOST=http://localhost:1234 gem push my-awesome-lib.gem
9
+ $ gem install my-awesome-lib --source http://localhost:1234
10
+
11
+ = TODO
12
+
13
+ * add config.ru
14
+ * --daemonize
15
+
16
+ == Note on Patches/Pull Requests
17
+
18
+ * Fork the project.
19
+ * Make your feature addition or bug fix.
20
+ * Add tests for it. This is important so I don't break it in a
21
+ future version unintentionally.
22
+ * Commit, do not mess with rakefile, version, or history.
23
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
24
+ * Send me a pull request. Bonus points for topic branches.
25
+
26
+ == Copyright
27
+
28
+ Copyright (c) 2010 Jari Bakken. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "gemrepo"
8
+ gem.summary = %Q{A simple gem server, useful for internal gem repos}
9
+ gem.description = %Q{A simple gem server that supports gem push / install.}
10
+ gem.email = "jari.bakken@gmail.com"
11
+ gem.homepage = "http://github.com/jarib/gemrepo"
12
+ gem.authors = ["Jari Bakken"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_development_dependency "rack-test", ">= 0.5.3"
15
+ gem.add_dependency "sinatra", ">= 1.0"
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/gemrepo ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'gemrepo'
4
+ require 'optparse'
5
+
6
+ options = {:port => 1234, :gemdir => File.expand_path("~/.gemrepo"), :handler => Rack::Handler::WEBrick }
7
+
8
+ parser = OptionParser.new do |opts|
9
+ opts.banner = "USAGE: gemrepo [options]"
10
+
11
+ opts.separator ""
12
+ opts.on "-p", "--port PORT", "use PORT (default: #{options[:port]})" do |port|
13
+ options[:port] = port
14
+ end
15
+
16
+ opts.on "-d", "--directory DIR", "use DIR as gem directory (default: #{options[:gemdir]})" do |dir|
17
+ options[:gemdir] = dir
18
+ end
19
+
20
+ opts.on "-s", "--server SERVER", "server to use (webrick/mongrel/thin, default: webrick)" do |s|
21
+ case s
22
+ when 'mongrel'
23
+ options[:handler] = Rack::Handler::Mongrel
24
+ when 'thin'
25
+ options[:handler] = Rack::Handler::Thin
26
+ else
27
+ # default: webrick
28
+ end
29
+ end
30
+
31
+ opts.on "-h", "--help" do
32
+ puts opts
33
+ exit
34
+ end
35
+
36
+ end
37
+
38
+ parser.parse!(ARGV)
39
+
40
+ GemRepo.set :gemdir, options[:gemdir]
41
+ FileUtils.mkdir_p options[:gemdir]
42
+
43
+ options[:handler].run GemRepo, :Port => options[:port]
44
+
45
+
46
+
47
+
data/lib/gemrepo.rb ADDED
@@ -0,0 +1,53 @@
1
+ require 'sinatra/base'
2
+ require 'rubygems/indexer'
3
+ require 'fileutils'
4
+
5
+ class GemRepo < Sinatra::Base
6
+
7
+ disable :show_exceptions
8
+ set :public, lambda { gemdir }
9
+
10
+ post "/api/v1/gems" do
11
+ if pull_spec
12
+ save
13
+ reindex
14
+ "Successfully registered gem: #{@spec.name}"
15
+ else
16
+ error 422, "invalid gem"
17
+ end
18
+ end
19
+
20
+ def pull_spec
21
+ format = Gem::Format.from_io request.body
22
+ @spec = format.spec
23
+ rescue Exception => ex
24
+ puts ex.message
25
+ false
26
+ end
27
+
28
+ def save
29
+ path = "#{gem_repository}/#{@spec.original_name}.gem"
30
+ File.open(path, "wb") { |io|
31
+ io << request.body.string
32
+ }
33
+ end
34
+
35
+ def reindex
36
+ indexer.generate_index
37
+ end
38
+
39
+ def gem_repository
40
+ @gem_repository ||= (
41
+ dir = File.join(settings.gemdir, "gems")
42
+ FileUtils.mkdir_p(dir) unless File.directory?(dir)
43
+
44
+ dir
45
+ )
46
+ end
47
+
48
+ def indexer
49
+ @indexer = Gem::Indexer.new settings.gemdir
50
+ end
51
+ end
52
+
53
+
@@ -0,0 +1,36 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe GemRepo do
4
+ before(:all) { GemRepo.set :gemdir, gemdir }
5
+ after { clear_gemdir }
6
+
7
+ it "should fail if the pushed gem is invalid" do
8
+ post "/api/v1/gems"
9
+
10
+ last_response.status.should == 422
11
+ last_response.body.should == "invalid gem"
12
+ end
13
+
14
+ it "should succeed if the pushed gem is valid" do
15
+ current_gems.should be_empty
16
+ current_index.should be_nil
17
+
18
+ post "/api/v1/gems", sample_gem
19
+
20
+ last_response.should be_ok
21
+ last_response.body.should == "Successfully registered gem: sample"
22
+
23
+ current_gems.size.should == 1
24
+ current_index.should_not be_nil
25
+ end
26
+
27
+ it "should serve the index" do
28
+ create_index
29
+
30
+ get "/yaml"
31
+
32
+ last_response.should be_ok
33
+ YAML.load(last_response.body).should be_kind_of(Gem::SourceIndex)
34
+ end
35
+
36
+ end
Binary file
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,57 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'gemrepo'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+ require 'rack/test'
7
+ require 'yaml'
8
+ require 'pp'
9
+
10
+ module GemRepoHelper
11
+ def app
12
+ GemRepo
13
+ end
14
+
15
+ def gemdir
16
+ File.join(File.dirname(__FILE__), 'tmp')
17
+ end
18
+
19
+ def clear_gemdir
20
+ FileUtils.rm_rf(gemdir)
21
+ end
22
+
23
+ def current_gems
24
+ Dir["#{gemdir}/gems/*.gem"]
25
+ end
26
+
27
+ def sample_gem
28
+ File.open(sample_gem_path, "rb") do |io|
29
+ return io.read
30
+ end
31
+ end
32
+
33
+ def sample_gem_path
34
+ File.join(File.dirname(__FILE__), 'sample-0.0.1.gem')
35
+ end
36
+
37
+ def current_index
38
+ file = "#{gemdir}/yaml"
39
+ YAML.load_file(file) if File.exist? file
40
+ end
41
+
42
+ def create_index
43
+ dir = "#{gemdir}/gems"
44
+
45
+ FileUtils.mkdir_p dir
46
+ FileUtils.cp sample_gem_path, dir
47
+ Gem::Indexer.new(gemdir).generate_index
48
+ end
49
+ end
50
+
51
+
52
+ Spec::Runner.configure do |config|
53
+ config.include Rack::Test::Methods
54
+ config.include GemRepoHelper
55
+ end
56
+
57
+
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gemrepo
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Jari Bakken
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-13 00:00:00 +02:00
19
+ default_executable: gemrepo
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 9
34
+ version: 1.2.9
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rack-test
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 13
46
+ segments:
47
+ - 0
48
+ - 5
49
+ - 3
50
+ version: 0.5.3
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: sinatra
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 15
62
+ segments:
63
+ - 1
64
+ - 0
65
+ version: "1.0"
66
+ type: :runtime
67
+ version_requirements: *id003
68
+ description: A simple gem server that supports gem push / install.
69
+ email: jari.bakken@gmail.com
70
+ executables:
71
+ - gemrepo
72
+ extensions: []
73
+
74
+ extra_rdoc_files:
75
+ - LICENSE
76
+ - README.rdoc
77
+ files:
78
+ - .document
79
+ - .gitignore
80
+ - LICENSE
81
+ - README.rdoc
82
+ - Rakefile
83
+ - VERSION
84
+ - bin/gemrepo
85
+ - lib/gemrepo.rb
86
+ - spec/gemrepo_spec.rb
87
+ - spec/sample-0.0.1.gem
88
+ - spec/spec.opts
89
+ - spec/spec_helper.rb
90
+ has_rdoc: true
91
+ homepage: http://github.com/jarib/gemrepo
92
+ licenses: []
93
+
94
+ post_install_message:
95
+ rdoc_options:
96
+ - --charset=UTF-8
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ hash: 3
114
+ segments:
115
+ - 0
116
+ version: "0"
117
+ requirements: []
118
+
119
+ rubyforge_project:
120
+ rubygems_version: 1.3.7
121
+ signing_key:
122
+ specification_version: 3
123
+ summary: A simple gem server, useful for internal gem repos
124
+ test_files:
125
+ - spec/spec_helper.rb
126
+ - spec/gemrepo_spec.rb