gem-insturl 0.1.0 → 0.1.1
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/README.md +1 -1
- data/VERSION +1 -1
- data/gem-insturl.gemspec +3 -3
- data/lib/rubygems/commands/insturl_command.rb +168 -128
- metadata +3 -3
data/README.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/gem-insturl.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "gem-insturl"
|
3
|
-
s.version = "0.1.
|
4
|
-
s.date = "2013-05-
|
3
|
+
s.version = "0.1.1"
|
4
|
+
s.date = "2013-05-03"
|
5
5
|
|
6
6
|
s.summary = "Gem plugin that installs a gem from a URL"
|
7
7
|
s.description = <<EOF
|
@@ -22,5 +22,5 @@ EOF
|
|
22
22
|
["README.md", "VERSION", "gem-insturl.gemspec"]
|
23
23
|
|
24
24
|
s.platform = Gem::Platform::RUBY
|
25
|
-
s.required_ruby_version = ">= 1.
|
25
|
+
s.required_ruby_version = ">= 1.8.7"
|
26
26
|
end
|
@@ -1,128 +1,168 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
If
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
def
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
end
|
1
|
+
require 'rubygems/commands/build_command'
|
2
|
+
require 'rubygems/commands/install_command'
|
3
|
+
|
4
|
+
class Gem::Commands::InsturlCommand < Gem::Command
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
super "insturl", "Install a gem from a URL"
|
8
|
+
|
9
|
+
add_option("--git", "use `git clone' to fetch the URL") do |val, opt|
|
10
|
+
options[:git] = true
|
11
|
+
end
|
12
|
+
|
13
|
+
add_option("--override", "install even if already exists") do |val, opt|
|
14
|
+
options[:override] = true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def description
|
19
|
+
<<EOF
|
20
|
+
The insturl command installs a gem from a URL.
|
21
|
+
|
22
|
+
Examples:
|
23
|
+
* gem insturl http://foo.com/bar.gem
|
24
|
+
* gem insturl http://foo.com/bar.tar.gz
|
25
|
+
* gem insturl --git http://foo.com/bar.git
|
26
|
+
|
27
|
+
Download:
|
28
|
+
If --git is specified, the URL is treated as a repository and cloned
|
29
|
+
with `git`; otherwise it is treated as a package file and downloaded
|
30
|
+
with `wget`. You must have git or wget installed in PATH.
|
31
|
+
|
32
|
+
Installation:
|
33
|
+
If --git is omitted and the URL ends with .gem, it is installed with
|
34
|
+
`gem install` directly after download.
|
35
|
+
|
36
|
+
If the URL is a repository or .zip/.tar.gz package, it must have a
|
37
|
+
valid *gemspec* file in top level directory. A gem is built from the
|
38
|
+
gemspec file and then installed.
|
39
|
+
EOF
|
40
|
+
end
|
41
|
+
|
42
|
+
def arguments
|
43
|
+
<<EOF
|
44
|
+
URL location of the package or git repository
|
45
|
+
If --git not set, URL should end with .gem/.zip/.tar.gz
|
46
|
+
EOF
|
47
|
+
end
|
48
|
+
|
49
|
+
def usage
|
50
|
+
"#{program_name} URL"
|
51
|
+
end
|
52
|
+
|
53
|
+
def execute
|
54
|
+
require 'tempfile'
|
55
|
+
require 'fileutils'
|
56
|
+
|
57
|
+
url = options[:args].first
|
58
|
+
raise Gem::Exception.new("URL is missing") if url.nil?
|
59
|
+
|
60
|
+
# check package format
|
61
|
+
unless options[:git]
|
62
|
+
pkgname = File.basename url
|
63
|
+
unless pkgname.end_with? ".gem" or
|
64
|
+
pkgname.end_with? ".zip" or
|
65
|
+
pkgname.end_with? ".tar.gz"
|
66
|
+
raise Gem::Exception.new("unsupported package format")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
dir = Dir.mktmpdir
|
71
|
+
begin
|
72
|
+
if options[:git]
|
73
|
+
return unless system("git clone #{url} #{dir}")
|
74
|
+
|
75
|
+
Dir.chdir dir do
|
76
|
+
install_gemspec
|
77
|
+
end
|
78
|
+
else
|
79
|
+
Dir.chdir dir do
|
80
|
+
# download
|
81
|
+
return unless system("wget -O #{pkgname} #{url}")
|
82
|
+
|
83
|
+
if pkgname.end_with? ".gem"
|
84
|
+
install_gem pkgname
|
85
|
+
else
|
86
|
+
# extract
|
87
|
+
if pkgname.end_with? ".zip"
|
88
|
+
return unless system("unzip #{pkgname}")
|
89
|
+
else
|
90
|
+
return unless system("tar xzf #{pkgname}")
|
91
|
+
end
|
92
|
+
|
93
|
+
# get dirname (FIXME)
|
94
|
+
dir2 = File.basename pkgname, ".zip"
|
95
|
+
|
96
|
+
Dir.chdir dir2 do
|
97
|
+
install_gemspec
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
ensure
|
103
|
+
FileUtils.rm_rf dir
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# install from a gemspec file
|
108
|
+
def install_gemspec
|
109
|
+
# find gemspec file
|
110
|
+
gemspecs = Dir['*.gemspec']
|
111
|
+
if gemspecs.size == 0
|
112
|
+
raise Gem::Exception.new("gemspec not found")
|
113
|
+
elsif gemspecs.size > 1
|
114
|
+
raise Gem::Exception.new("multiple gemspecs found")
|
115
|
+
end
|
116
|
+
gemspec = gemspecs[0]
|
117
|
+
|
118
|
+
# load gemspec file
|
119
|
+
spec = eval File.read(gemspec)
|
120
|
+
name, version = spec.name, spec.version
|
121
|
+
|
122
|
+
# prevent overriding
|
123
|
+
unless options[:override]
|
124
|
+
find_gem_versions(name).each do |vsn|
|
125
|
+
if vsn == version
|
126
|
+
err = "#{name} #{version} has already been installed"
|
127
|
+
raise Gem::Exception.new(err)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# build and install
|
133
|
+
build_gem gemspec
|
134
|
+
install_gem "#{name}-#{version}.gem"
|
135
|
+
end
|
136
|
+
|
137
|
+
# Find installed versions of the gem.
|
138
|
+
# Return a sequence of Gem::Version instances.
|
139
|
+
def find_gem_versions(name)
|
140
|
+
find_gem_specs(name).map{|spec| spec.version}
|
141
|
+
end
|
142
|
+
|
143
|
+
# Find installed versions of the gem.
|
144
|
+
# Return a sequence of Gem::Specification instances.
|
145
|
+
def find_gem_specs(name)
|
146
|
+
if Gem::Specification.respond_to? :find_all_by_name
|
147
|
+
Gem::Specification.find_all_by_name name
|
148
|
+
elsif Gem.respond_to? :source_index and
|
149
|
+
Gem.source_index.respond_to? :find_name
|
150
|
+
Gem.source_index.find_name name
|
151
|
+
else
|
152
|
+
raise Gem::Exception.new("unsupported gem version")
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
# Build a gem from a gemspec file.
|
157
|
+
# e.g. gem-insturl.gemspec -> gem-insturl-0.1.0.gem
|
158
|
+
def build_gem(gemspec_file)
|
159
|
+
Gem::Commands::BuildCommand.new.invoke gemspec_file
|
160
|
+
end
|
161
|
+
|
162
|
+
# Install a gem.
|
163
|
+
# e.g. gem-insturl-0.1.0.gem
|
164
|
+
def install_gem(gem_file)
|
165
|
+
Gem::Commands::InstallCommand.new.invoke gem_file
|
166
|
+
end
|
167
|
+
|
168
|
+
end # class Gem::Commands::InsturlCommand
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem-insturl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-03 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! 'The insturl command installs a gem from a URL.
|
15
15
|
|
@@ -46,7 +46,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
46
|
requirements:
|
47
47
|
- - ! '>='
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 1.
|
49
|
+
version: 1.8.7
|
50
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|