geminabox 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of geminabox might be problematic. Click here for more details.
- data/README.markdown +9 -1
- data/lib/rubygems/commands/inabox_command.rb +123 -0
- data/lib/rubygems_plugin.rb +7 -0
- data/views/upload.erb +1 -0
- metadata +4 -2
data/README.markdown
CHANGED
@@ -8,7 +8,7 @@ Gem in a box is a simple [sinatra][sinatra] app to allow you to host your own ow
|
|
8
8
|
|
9
9
|
It has no security, or authentication so you should handle this yourself.
|
10
10
|
|
11
|
-
##
|
11
|
+
## Server Setup
|
12
12
|
|
13
13
|
gem install geminabox
|
14
14
|
|
@@ -23,6 +23,14 @@ Create a config.ru as follows:
|
|
23
23
|
And finally, hook up the config.ru as you normally would ([passenger][passenger], [thin][thin], [unicorn][unicorn], whatever floats you boat).
|
24
24
|
|
25
25
|
|
26
|
+
## Client Usage
|
27
|
+
|
28
|
+
gem install geminabox
|
29
|
+
|
30
|
+
gem inabox pkg/my-awesome-gem-1.0.gem
|
31
|
+
|
32
|
+
Simples!
|
33
|
+
|
26
34
|
[sinatra]: http://www.sinatrarb.com/
|
27
35
|
[passenger]: http://www.modrails.com/
|
28
36
|
[thin]: http://code.macournoyer.com/thin/
|
@@ -0,0 +1,123 @@
|
|
1
|
+
class Gem::Commands::InaboxCommand < Gem::Command
|
2
|
+
def description
|
3
|
+
'Push a gem up to your GemInABox'
|
4
|
+
end
|
5
|
+
|
6
|
+
def arguments
|
7
|
+
"GEM built gem to push up"
|
8
|
+
end
|
9
|
+
|
10
|
+
def usage
|
11
|
+
"#{program_name} GEM"
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
super 'inabox', description
|
16
|
+
|
17
|
+
add_option('-c', '--configure', "Configure GemInABox") do |value, options|
|
18
|
+
options[:configure] = true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def execute
|
23
|
+
return configure if options[:configure]
|
24
|
+
setup
|
25
|
+
send_gem
|
26
|
+
end
|
27
|
+
|
28
|
+
def setup
|
29
|
+
@gemfile = get_one_gem_name
|
30
|
+
configure unless geminabox_host
|
31
|
+
end
|
32
|
+
|
33
|
+
def send_gem
|
34
|
+
say "Pushing gem to #{geminabox_host}..."
|
35
|
+
|
36
|
+
File.open(@gemfile, "rb") do |file|
|
37
|
+
url = URI.parse(geminabox_host)
|
38
|
+
query, headers = Multipart::MultipartPost.new.prepare_query("file" => file)
|
39
|
+
|
40
|
+
Net::HTTP.start(url.host, url.port) {|con|
|
41
|
+
con.read_timeout = 5
|
42
|
+
response = con.post("/upload", query, headers)
|
43
|
+
puts response.body
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
def config_path
|
50
|
+
File.join(Gem.user_home, '.gem', 'geminabox')
|
51
|
+
end
|
52
|
+
|
53
|
+
def configure
|
54
|
+
say "Enter the root url for your personal geminabox instance. (E.g. http://gems/)"
|
55
|
+
host = ask("Host:")
|
56
|
+
self.geminabox_host = host
|
57
|
+
end
|
58
|
+
|
59
|
+
def geminabox_host
|
60
|
+
geminabox_host ||= Gem.configuration.load_file(config_path)[:host]
|
61
|
+
end
|
62
|
+
|
63
|
+
def geminabox_host=(host)
|
64
|
+
config = Gem.configuration.load_file(config_path).merge(:host => host)
|
65
|
+
|
66
|
+
dirname = File.dirname(config_path)
|
67
|
+
Dir.mkdir(dirname) unless File.exists?(dirname)
|
68
|
+
|
69
|
+
File.open(config_path, 'w') do |f|
|
70
|
+
f.write config.to_yaml
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
module Multipart
|
75
|
+
require 'rubygems'
|
76
|
+
require 'mime/types'
|
77
|
+
require 'net/http'
|
78
|
+
require 'cgi'
|
79
|
+
|
80
|
+
class Param
|
81
|
+
attr_accessor :k, :v
|
82
|
+
def initialize( k, v )
|
83
|
+
@k = k
|
84
|
+
@v = v
|
85
|
+
end
|
86
|
+
|
87
|
+
def to_multipart
|
88
|
+
return "Content-Disposition: form-data; name=\"#{k}\"\r\n\r\n#{v}\r\n"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
class FileParam
|
93
|
+
attr_accessor :k, :filename, :content
|
94
|
+
def initialize( k, filename, content )
|
95
|
+
@k = k
|
96
|
+
@filename = filename
|
97
|
+
@content = content
|
98
|
+
end
|
99
|
+
|
100
|
+
def to_multipart
|
101
|
+
return "Content-Disposition: form-data; name=\"#{k}\"; filename=\"#{filename}\"\r\n" + "Content-Transfer-Encoding: binary\r\n" + "Content-Type: #{MIME::Types.type_for(@filename)}\r\n\r\n" + content + "\r\n"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
class MultipartPost
|
106
|
+
BOUNDARY = 'tarsiers-rule0000'
|
107
|
+
HEADER = {"Content-type" => "multipart/form-data, boundary=" + BOUNDARY + " "}
|
108
|
+
|
109
|
+
def prepare_query(params)
|
110
|
+
fp = []
|
111
|
+
params.each {|k,v|
|
112
|
+
if v.respond_to?(:read)
|
113
|
+
fp.push(FileParam.new(k, v.path, v.read))
|
114
|
+
else
|
115
|
+
fp.push(Param.new(k,v))
|
116
|
+
end
|
117
|
+
}
|
118
|
+
query = fp.collect {|p| "--" + BOUNDARY + "\r\n" + p.to_multipart }.join("") + "--" + BOUNDARY + "--"
|
119
|
+
return query, HEADER
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
data/views/upload.erb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geminabox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Lea
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-27 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -44,6 +44,8 @@ files:
|
|
44
44
|
- README.markdown
|
45
45
|
- lib/geminabox.rb
|
46
46
|
- lib/hostess.rb
|
47
|
+
- lib/rubygems/commands/inabox_command.rb
|
48
|
+
- lib/rubygems_plugin.rb
|
47
49
|
- public/master.css
|
48
50
|
- views/index.erb
|
49
51
|
- views/layout.erb
|