gem-insturl 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -29,4 +29,4 @@ If it is a git repository or .zip/.tar.gz package, then it must have a valid **g
29
29
  Requirements
30
30
  -------------
31
31
 
32
- Ruby *>= 1.9.1* is required. I am not sure if it could work on *1.8.7*.
32
+ Ruby *>= 1.8.7* is tested. Rubygems *>= 1.3.7* is tested.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
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.0"
4
- s.date = "2013-05-02"
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.9.1"
25
+ s.required_ruby_version = ">= 1.8.7"
26
26
  end
@@ -1,128 +1,168 @@
1
- class Gem::Commands::InsturlCommand < Gem::Command
2
-
3
- def initialize
4
- super "insturl", "Install a gem from a URL"
5
-
6
- add_option("--git", "use `git clone' to fetch the URL") do |value, options|
7
- options[:git] = true
8
- end
9
-
10
- add_option("--force", "install even if already installed") do |value, options|
11
- options[:force] = true
12
- end
13
- end
14
-
15
- def description
16
- <<EOF
17
- The insturl command installs a gem from a URL.
18
-
19
- Examples:
20
- * gem insturl http://foo.com/bar.gem
21
- * gem insturl http://foo.com/bar.tar.gz
22
- * gem insturl --git http://foo.com/bar.git
23
-
24
- If --git is specified, the gem is fetched by `git clone URL`;
25
- otherwise it is downloaded with `wget` (you must have wget in PATH)
26
-
27
- If the URL ends with .gem, it is directly installed after download.
28
- If it is a git repository or .zip/.tar.gz package, then it must have
29
- a valid *gemspec* file in top level directory.
30
- EOF
31
- end
32
-
33
- def arguments
34
- "URL location of the package or git repository\n" +
35
- " If --git not set, URL should end with .gem/.zip/.tar.gz"
36
- end
37
-
38
- def usage
39
- "#{program_name} URL"
40
- end
41
-
42
- def execute
43
- require 'tempfile'
44
- require 'fileutils'
45
-
46
- url = options[:args].first
47
- raise ArgumentError.new("URL is missing") if url.nil?
48
-
49
- # check package format
50
- unless options[:git]
51
- pkgname = File.basename url
52
- unless pkgname.end_with? ".gem" or
53
- pkgname.end_with? ".zip" or
54
- pkgname.end_with? ".tar.gz"
55
- raise ArgumentError.new("unsupported package format")
56
- end
57
- end
58
-
59
- dir = Dir.mktmpdir
60
- begin
61
- if options[:git]
62
- return unless system("git clone #{url} #{dir}")
63
-
64
- Dir.chdir dir do
65
- install_gemspec
66
- end
67
- else
68
- Dir.chdir dir do
69
- # download the package
70
- return unless system("wget -O #{pkgname} #{url}")
71
-
72
- # install the package
73
- if pkgname.end_with? ".gem"
74
- system("gem install #{pkgname}")
75
- elsif pkgname.end_with? ".zip"
76
- return unless ok system("unzip #{pkgname}")
77
-
78
- dir2 = File.basename pkgname, ".zip"
79
- Dir.chdir dir2 do
80
- install_gemspec
81
- end
82
- elsif pkgname.end_with? ".tar.gz"
83
- return unless system("tar xzf #{pkgname}")
84
-
85
- dir2 = File.basename pkgname, ".tar.gz"
86
- Dir.chdir dir2 do
87
- install_gemspec
88
- end
89
- end
90
- end
91
- end
92
- ensure
93
- FileUtils.rm_rf dir
94
- end
95
- end
96
-
97
- # install from a gemspec file
98
- def install_gemspec
99
- # find gemspec file
100
- gemspecs = Dir['*.gemspec']
101
- if gemspecs.size == 0
102
- raise ArgumentError.new("gemspec not found")
103
- elsif gemspecs.size > 1
104
- raise ArgumentError.new("multiple gemspecs found")
105
- end
106
- gemspec = gemspecs[0]
107
-
108
- # check if the same gem has been installed
109
- specobj = eval File.read(gemspec)
110
- unless options[:force]
111
- Gem::Specification.find_all do |spec|
112
- if spec.name == specobj.name and
113
- spec.version == specobj.version
114
- err = "#{spec.name} #{spec.version} has already been installed"
115
- raise ArgumentError.new(err)
116
- end
117
- end
118
- end
119
-
120
- # build gem
121
- return unless system("gem build #{gemspec}")
122
-
123
- # install gem
124
- gem = "#{specobj.name}-#{specobj.version}.gem"
125
- system("gem install #{gem}")
126
- end
127
-
128
- end # class Gem::Commands::InsturlCommand
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.0
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-02 00:00:00.000000000 Z
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.9.1
49
+ version: 1.8.7
50
50
  required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements: