gem-insturl 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +32 -0
- data/VERSION +1 -0
- data/gem-insturl.gemspec +26 -0
- data/lib/rubygems/commands/insturl_command.rb +128 -0
- data/lib/rubygems_plugin.rb +2 -0
- metadata +63 -0
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
gem-insturl
|
2
|
+
===========
|
3
|
+
|
4
|
+
This is a [rubygems](http://rubygems.org/) plugin that installs a gem from a URL.
|
5
|
+
|
6
|
+
It add a *insturl* command to *gem*.
|
7
|
+
|
8
|
+
Installation
|
9
|
+
-------------
|
10
|
+
|
11
|
+
`gem install gem-insturl`
|
12
|
+
|
13
|
+
Usage
|
14
|
+
------
|
15
|
+
|
16
|
+
Examples:
|
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*
|
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)
|
24
|
+
|
25
|
+
If the URL ends with `.gem`, it is directly installed with `gem install GEMNAME` after download.
|
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.
|
28
|
+
|
29
|
+
Requirements
|
30
|
+
-------------
|
31
|
+
|
32
|
+
Ruby *>= 1.9.1* is required. I am not sure if it could work on *1.8.7*.
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/gem-insturl.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "gem-insturl"
|
3
|
+
s.version = "0.1.0"
|
4
|
+
s.date = "2013-05-02"
|
5
|
+
|
6
|
+
s.summary = "Gem plugin that installs a gem from a URL"
|
7
|
+
s.description = <<EOF
|
8
|
+
The insturl command installs a gem from a URL.
|
9
|
+
|
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
|
14
|
+
EOF
|
15
|
+
|
16
|
+
s.authors = ["physacco"]
|
17
|
+
s.email = ["physacco@gmail.com"]
|
18
|
+
s.homepage = "https://github.com/physacco/gem-insturl"
|
19
|
+
s.license = "MIT"
|
20
|
+
|
21
|
+
s.files = Dir["lib/**/*.rb"] +
|
22
|
+
["README.md", "VERSION", "gem-insturl.gemspec"]
|
23
|
+
|
24
|
+
s.platform = Gem::Platform::RUBY
|
25
|
+
s.required_ruby_version = ">= 1.9.1"
|
26
|
+
end
|
@@ -0,0 +1,128 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gem-insturl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- physacco
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-02 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! 'The insturl command installs a gem from a URL.
|
15
|
+
|
16
|
+
|
17
|
+
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
|
+
'
|
26
|
+
email:
|
27
|
+
- physacco@gmail.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- lib/rubygems_plugin.rb
|
33
|
+
- lib/rubygems/commands/insturl_command.rb
|
34
|
+
- README.md
|
35
|
+
- VERSION
|
36
|
+
- gem-insturl.gemspec
|
37
|
+
homepage: https://github.com/physacco/gem-insturl
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.9.1
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.8.23
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: Gem plugin that installs a gem from a URL
|
62
|
+
test_files: []
|
63
|
+
has_rdoc:
|