gem-insturl 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5d06f4b21a78db285dedb0c6d01b9cb5cf48fda4
4
+ data.tar.gz: ae0712ef9bacac100dd9c9844e56806bb693e003
5
+ SHA512:
6
+ metadata.gz: 923b616fbd64f84fb35dbfdf9f2c560b7ae6ad79d5dc26fdfc08241e447e6bbf59e26375b171c62fb0a8fa4529f4b96c7379e9d6ca7688627720f5eaa88e83a8
7
+ data.tar.gz: 87c1c3bf91a48a274a43e2c5db098ef7a2d4ad3f9a0e4e257188b11ae46d39e553e5211b3095bb65c3abfb1420d369502080d1078c1d8b522c4b47fd1873a250
data/README.md CHANGED
@@ -15,16 +15,17 @@ Usage
15
15
 
16
16
  Examples:
17
17
 
18
- * gem insturl *http://foo.com/bar.gem*
19
- * gem insturl *http://foo.com/bar.tar.gz*
20
- * gem insturl --git *http://foo.com/bar.git*
18
+ * gem **insturl** http://.../foo.git
19
+ * gem **insturl** http://.../foo.gem
20
+ * gem **insturl** http://.../foo.tar.gz
21
21
 
22
- If --git is specified, the gem is fetched by `git clone URL`;
23
- otherwise it is downloaded with `wget` (you must have [wget](http://www.gnu.org/software/wget/) in PATH)
22
+ If --git is specified or the URL ends with .git, it is treated as a git repository and cloned with `git`;
23
+ otherwise it is treated as a package file and downloaded with `wget`. You must have git or wget installed in PATH.
24
24
 
25
- If the URL ends with `.gem`, it is directly installed with `gem install GEMNAME` after download.
25
+ If --git is omitted and the URL ends with .gem, it is installed with `gem install` directly after download.
26
26
 
27
- If it is a git repository or .zip/.tar.gz package, then it must have a valid **gemspec** file in top level directory.
27
+ If the URL is a repository or a .zip/.tar.gz package, it must have a valid *gemspec* file in top level directory.
28
+ A gem is built from the gemspec file and then installed.
28
29
 
29
30
  Requirements
30
31
  -------------
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/gem-insturl.gemspec CHANGED
@@ -1,16 +1,16 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "gem-insturl"
3
- s.version = "0.1.1"
4
- s.date = "2013-05-03"
3
+ s.version = "0.1.2"
4
+ s.date = "2013-05-13"
5
5
 
6
6
  s.summary = "Gem plugin that installs a gem from a URL"
7
7
  s.description = <<EOF
8
8
  The insturl command installs a gem from a URL.
9
9
 
10
10
  Examples:
11
- * gem insturl http://foo.com/bar.gem
12
- * gem insturl http://foo.com/bar.tar.gz
13
- * gem insturl --git http://foo.com/bar.git
11
+ * gem **insturl** http://.../foo.git
12
+ * gem **insturl** http://.../foo.gem
13
+ * gem **insturl** http://.../foo.tar.gz
14
14
  EOF
15
15
 
16
16
  s.authors = ["physacco"]
@@ -1,6 +1,3 @@
1
- require 'rubygems/commands/build_command'
2
- require 'rubygems/commands/install_command'
3
-
4
1
  class Gem::Commands::InsturlCommand < Gem::Command
5
2
 
6
3
  def initialize
@@ -20,30 +17,28 @@ class Gem::Commands::InsturlCommand < Gem::Command
20
17
  The insturl command installs a gem from a URL.
21
18
 
22
19
  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
20
+ * gem insturl http://.../foo.git
21
+ * gem insturl http://.../foo.gem
22
+ * gem insturl http://.../foo.tar.gz
26
23
 
27
24
  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.
25
+ If --git is specified or the URL ends with .git, it is treated as a
26
+ git repository and cloned with `git`; otherwise it is treated as a
27
+ package file and downloaded with `wget`. You must have git or wget
28
+ installed in PATH.
31
29
 
32
30
  Installation:
33
31
  If --git is omitted and the URL ends with .gem, it is installed with
34
32
  `gem install` directly after download.
35
33
 
36
- If the URL is a repository or .zip/.tar.gz package, it must have a
34
+ If the URL is a repository or a .zip/.tar.gz package, it must have a
37
35
  valid *gemspec* file in top level directory. A gem is built from the
38
36
  gemspec file and then installed.
39
37
  EOF
40
38
  end
41
39
 
42
40
  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
41
+ "URL location of the package or git repository"
47
42
  end
48
43
 
49
44
  def usage
@@ -51,58 +46,93 @@ EOF
51
46
  end
52
47
 
53
48
  def execute
54
- require 'tempfile'
55
- require 'fileutils'
56
-
57
49
  url = options[:args].first
58
50
  raise Gem::Exception.new("URL is missing") if url.nil?
59
51
 
60
52
  # 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
53
+ format = determine_package_format url, options
69
54
 
55
+ require 'tempfile'
70
56
  dir = Dir.mktmpdir
71
57
  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
58
+ Dir.chdir dir do
59
+ send "install_from_#{format}", url
101
60
  end
102
61
  ensure
62
+ require 'fileutils'
103
63
  FileUtils.rm_rf dir
104
64
  end
105
65
  end
66
+
67
+ def determine_package_format(url, options={})
68
+ return :git if options[:git]
69
+
70
+ name = File.basename url
71
+ if name.end_with? ".git"
72
+ :git
73
+ elsif name.end_with? ".gem"
74
+ :gem
75
+ elsif name.end_with? ".tgz"
76
+ :tgz
77
+ elsif name.end_with? ".tar.gz"
78
+ :tgz
79
+ elsif name.end_with? ".zip"
80
+ :zip
81
+ else
82
+ raise Gem::FormatException, "unsupported package format"
83
+ end
84
+ end
85
+
86
+ def install_from_git(url)
87
+ return unless system("git clone #{url}")
88
+
89
+ topdir = subdirs_in_cwd.first
90
+
91
+ Dir.chdir topdir do
92
+ install_gemspec
93
+ end
94
+ end
95
+
96
+ def install_from_gem(url)
97
+ return unless system("wget #{url}")
98
+
99
+ pkgname = files_in_cwd.first
100
+
101
+ # extract gemspec
102
+ spec = get_gem_spec pkgname
103
+ name, version = spec.name, spec.version
104
+ prevent_overriding(name, version) unless options[:override]
105
+
106
+ install_gem pkgname
107
+ end
108
+
109
+ def install_from_tgz(url)
110
+ return unless system("wget #{url}")
111
+
112
+ pkgname = files_in_cwd.first
113
+
114
+ return unless system("tar xzf #{pkgname}")
115
+
116
+ topdir = subdirs_in_cwd.first
117
+
118
+ Dir.chdir topdir do
119
+ install_gemspec
120
+ end
121
+ end
122
+
123
+ def install_from_zip(url)
124
+ return unless system("wget #{url}")
125
+
126
+ pkgname = files_in_cwd.first
127
+
128
+ return unless system("unzip #{pkgname}")
129
+
130
+ topdir = subdirs_in_cwd.first
131
+
132
+ Dir.chdir topdir do
133
+ install_gemspec
134
+ end
135
+ end
106
136
 
107
137
  # install from a gemspec file
108
138
  def install_gemspec
@@ -118,22 +148,23 @@ EOF
118
148
  # load gemspec file
119
149
  spec = eval File.read(gemspec)
120
150
  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
151
+ prevent_overriding(name, version) unless options[:override]
131
152
 
132
153
  # build and install
133
154
  build_gem gemspec
134
155
  install_gem "#{name}-#{version}.gem"
135
156
  end
136
157
 
158
+ # Abort if the gem has already been installed.
159
+ def prevent_overriding(name, version)
160
+ find_gem_versions(name).each do |vsn|
161
+ if vsn == version
162
+ err = "#{name} #{version} has already been installed"
163
+ raise Gem::Exception.new(err)
164
+ end
165
+ end
166
+ end
167
+
137
168
  # Find installed versions of the gem.
138
169
  # Return a sequence of Gem::Version instances.
139
170
  def find_gem_versions(name)
@@ -156,13 +187,39 @@ EOF
156
187
  # Build a gem from a gemspec file.
157
188
  # e.g. gem-insturl.gemspec -> gem-insturl-0.1.0.gem
158
189
  def build_gem(gemspec_file)
190
+ require 'rubygems/commands/build_command'
159
191
  Gem::Commands::BuildCommand.new.invoke gemspec_file
160
192
  end
161
193
 
162
194
  # Install a gem.
163
195
  # e.g. gem-insturl-0.1.0.gem
164
196
  def install_gem(gem_file)
197
+ require 'rubygems/commands/install_command'
165
198
  Gem::Commands::InstallCommand.new.invoke gem_file
166
199
  end
200
+
201
+ # Get specification of a gem file.
202
+ # Return a Gem::Specification instance.
203
+ def get_gem_spec(gem_file)
204
+ begin
205
+ require 'rubygems/format'
206
+ Gem::Format.from_file_by_path(gem_file).spec
207
+ rescue LoadError
208
+ require 'rubygems/package'
209
+ Gem::Package.new(gem_file).spec
210
+ end
211
+ end
212
+
213
+ # List files in current directory.
214
+ # Return an Array of String.
215
+ def files_in_cwd
216
+ Dir["*"].delete_if{|ent| !File.file?(ent)}
217
+ end
218
+
219
+ # List subdirectories in current directory.
220
+ # Return an Array of String.
221
+ def subdirs_in_cwd
222
+ Dir["*"].delete_if{|ent| !File.directory?(ent)}
223
+ end
167
224
 
168
225
  end # class Gem::Commands::InsturlCommand
metadata CHANGED
@@ -1,28 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem-insturl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
5
- prerelease:
4
+ version: 0.1.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - physacco
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-03 00:00:00.000000000 Z
11
+ date: 2013-05-13 00:00:00.000000000 Z
13
12
  dependencies: []
14
- description: ! 'The insturl command installs a gem from a URL.
15
-
13
+ description: |
14
+ The insturl command installs a gem from a URL.
16
15
 
17
16
  Examples:
18
-
19
- * gem insturl http://foo.com/bar.gem
20
-
21
- * gem insturl http://foo.com/bar.tar.gz
22
-
23
- * gem insturl --git http://foo.com/bar.git
24
-
25
- '
17
+ * gem **insturl** http://.../foo.git
18
+ * gem **insturl** http://.../foo.gem
19
+ * gem **insturl** http://.../foo.tar.gz
26
20
  email:
27
21
  - physacco@gmail.com
28
22
  executables: []
@@ -37,27 +31,26 @@ files:
37
31
  homepage: https://github.com/physacco/gem-insturl
38
32
  licenses:
39
33
  - MIT
34
+ metadata: {}
40
35
  post_install_message:
41
36
  rdoc_options: []
42
37
  require_paths:
43
38
  - lib
44
39
  required_ruby_version: !ruby/object:Gem::Requirement
45
- none: false
46
40
  requirements:
47
- - - ! '>='
41
+ - - '>='
48
42
  - !ruby/object:Gem::Version
49
43
  version: 1.8.7
50
44
  required_rubygems_version: !ruby/object:Gem::Requirement
51
- none: false
52
45
  requirements:
53
- - - ! '>='
46
+ - - '>='
54
47
  - !ruby/object:Gem::Version
55
48
  version: '0'
56
49
  requirements: []
57
50
  rubyforge_project:
58
- rubygems_version: 1.8.23
51
+ rubygems_version: 2.0.0
59
52
  signing_key:
60
- specification_version: 3
53
+ specification_version: 4
61
54
  summary: Gem plugin that installs a gem from a URL
62
55
  test_files: []
63
56
  has_rdoc: