gem-wrappers 1.1.0 → 1.2.0
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.
- checksums.yaml +4 -4
- data/Changelog.md +17 -0
- data/README.md +12 -0
- data/lib/gem-wrappers/command.rb +8 -11
- data/lib/gem-wrappers/command/file_exist.rb +7 -0
- data/lib/gem-wrappers/installer.rb +10 -2
- data/lib/gem-wrappers/specification.rb +11 -9
- data/lib/gem-wrappers/version.rb +1 -1
- data/test/gem-wrappers/command_test.rb +22 -0
- data/test/gem-wrappers/installer_test.rb +66 -0
- data/test/gem-wrappers/specification_and_version_test.rb +8 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13e6186794897ef3db5b1820064e22eb240457ea
|
4
|
+
data.tar.gz: 1138077c42d8823938ad6721e2f58e6bddff3e59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 145a27ac7bfac5918801818cce182d93bd79193aad0b76f47fde58f4414dd50e1555fbe4ca1ae853006289fe2f1c8c3cd552c3f612c9e1966bf378b70256dbc9
|
7
|
+
data.tar.gz: 077e28899433286c391babbaae5b82184134aeeee8f440010405947a0b9a214fe6d6c2e6b1f207931f3c31bf3839a56313d8d8f09d0f17bdb7dc6ef815f4260e
|
data/Changelog.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 1.2.0
|
4
|
+
date: 2013-12-20
|
5
|
+
|
6
|
+
- Add support for generating scripts wrappers
|
7
|
+
- Improved gems searching and tests
|
8
|
+
|
9
|
+
## 1.1.0
|
10
|
+
date: 2013-12-20
|
11
|
+
|
12
|
+
- Add functionality to uninstall wrappers when gem is uninstalled
|
13
|
+
|
14
|
+
## 1.0.0
|
15
|
+
date: 2013-12-19
|
16
|
+
|
17
|
+
- Stable version released
|
data/README.md
CHANGED
@@ -31,6 +31,18 @@ to rerun the process for all gems in `GEM_HOME` use:
|
|
31
31
|
gem wrappers regenerate
|
32
32
|
```
|
33
33
|
|
34
|
+
wrappers will be generated in `$GEM_HOME/wrappers/`.
|
35
|
+
|
36
|
+
## Generating scripts wrappers
|
37
|
+
|
38
|
+
It is possible to generate wrappers for custom scripts:
|
39
|
+
|
40
|
+
```bash
|
41
|
+
gem wrappers /path/to/script
|
42
|
+
```
|
43
|
+
|
44
|
+
a wrapper `$GEM_HOME/wrappers/script` will be generated.
|
45
|
+
|
34
46
|
## Showing current configuration
|
35
47
|
|
36
48
|
To see paths that are used by gem run:
|
data/lib/gem-wrappers/command.rb
CHANGED
@@ -2,6 +2,7 @@ require 'rubygems/command_manager'
|
|
2
2
|
require 'rubygems/installer'
|
3
3
|
require 'rubygems/version'
|
4
4
|
require 'gem-wrappers'
|
5
|
+
require 'gem-wrappers/specification'
|
5
6
|
|
6
7
|
class WrappersCommand < Gem::Command
|
7
8
|
def initialize
|
@@ -33,6 +34,8 @@ DOC
|
|
33
34
|
execute_show
|
34
35
|
when 'regenerate'
|
35
36
|
execute_regenerate
|
37
|
+
when FileExist
|
38
|
+
execute_regenerate([File.expand_path(subcommand)]) # TODO: File.expand_path not tested!
|
36
39
|
else
|
37
40
|
execute_unknown subcommand
|
38
41
|
end
|
@@ -50,22 +53,16 @@ DOC
|
|
50
53
|
false
|
51
54
|
end
|
52
55
|
|
53
|
-
def execute_regenerate
|
54
|
-
GemWrappers.install(
|
56
|
+
def execute_regenerate(list = executables)
|
57
|
+
GemWrappers.install(list)
|
55
58
|
end
|
56
59
|
|
57
60
|
private
|
58
61
|
|
59
62
|
def executables
|
60
63
|
# do not use map(&:...) - for ruby 1.8.6 compatibility
|
61
|
-
@executables ||= installed_gems.map{|gem| gem.executables }.inject{|sum, n| sum + n } || []
|
62
|
-
end
|
63
|
-
|
64
|
-
def installed_gems
|
65
|
-
if Gem::VERSION > '1.8' then
|
66
|
-
Gem::Specification.to_a
|
67
|
-
else
|
68
|
-
Gem.source_index.map{|name,spec| spec}
|
69
|
-
end
|
64
|
+
@executables ||= GemWrappers::Specification.installed_gems.map{|gem| gem.executables }.inject{|sum, n| sum + n } || []
|
70
65
|
end
|
71
66
|
end
|
67
|
+
|
68
|
+
require 'gem-wrappers/command/file_exist'
|
@@ -30,14 +30,22 @@ module GemWrappers
|
|
30
30
|
|
31
31
|
def install(executable)
|
32
32
|
raise "Missing environment file for initialize!" unless @environment_file
|
33
|
+
@executable = executable
|
33
34
|
content = ERB.new(template).result(binding)
|
34
|
-
file_name = File.join(wrappers_path, executable)
|
35
|
+
file_name = File.join(wrappers_path, File.basename(executable))
|
35
36
|
File.open(file_name, 'w') do |file|
|
36
37
|
file.write(content)
|
37
38
|
end
|
38
39
|
File.chmod(0755, file_name)
|
39
40
|
end
|
40
41
|
|
42
|
+
def executable_expanded
|
43
|
+
if File.extname(@executable) == ".rb"
|
44
|
+
then "ruby #{@executable}"
|
45
|
+
else @executable
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
41
49
|
def template
|
42
50
|
@template ||= <<-TEMPLATE
|
43
51
|
#!/usr/bin/env bash
|
@@ -46,7 +54,7 @@ if
|
|
46
54
|
[[ -s "<%= environment_file %>" ]]
|
47
55
|
then
|
48
56
|
source "<%= environment_file %>"
|
49
|
-
exec <%=
|
57
|
+
exec <%= executable_expanded %> "$@"
|
50
58
|
else
|
51
59
|
echo "ERROR: Missing RVM environment file: '<%= environment_file %>'" >&2
|
52
60
|
exit 1
|
@@ -1,15 +1,17 @@
|
|
1
1
|
module GemWrappers
|
2
2
|
module Specification
|
3
|
-
def self.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
rescue Gem::LoadError
|
11
|
-
nil
|
3
|
+
def self.installed_gems
|
4
|
+
if Gem::VERSION > '1.8' then
|
5
|
+
Gem::Specification.to_a
|
6
|
+
else
|
7
|
+
Gem.source_index.map{|name,spec| spec}
|
8
|
+
end
|
12
9
|
end
|
10
|
+
|
11
|
+
def self.find(name = "gem-wrappers")
|
12
|
+
@gem_wrappers_spec ||= installed_gems.find{|spec| spec.name == name }
|
13
|
+
end
|
14
|
+
|
13
15
|
def self.version
|
14
16
|
find ? find.version.to_s : nil
|
15
17
|
end
|
data/lib/gem-wrappers/version.rb
CHANGED
@@ -83,6 +83,28 @@ EXPECTED
|
|
83
83
|
$stderr.string.must_equal("")
|
84
84
|
$stdout.string.must_equal("")
|
85
85
|
end
|
86
|
+
|
87
|
+
it "generates script wrapper" do
|
88
|
+
FileUtils.mkdir_p(@test_path)
|
89
|
+
test_file = File.join(@test_path, "test_file.sh")
|
90
|
+
File.open(test_file, "w") do |file|
|
91
|
+
file.puts "echo test"
|
92
|
+
end
|
93
|
+
Gem.configuration[:wrappers_environment_file] = File.join(@test_path, "environment")
|
94
|
+
Gem.configuration[:wrappers_path] = File.join(@test_path, "wrappers")
|
95
|
+
|
96
|
+
subject.options[:args] = [test_file]
|
97
|
+
subject.execute
|
98
|
+
|
99
|
+
Gem.configuration[:wrappers_environment_file] = nil
|
100
|
+
Gem.configuration[:wrappers_path] = nil
|
101
|
+
|
102
|
+
File.exist?(File.join(@test_path, "environment")).must_equal(true)
|
103
|
+
File.exist?(File.join(@test_path, "wrappers", "test_file.sh")).must_equal(true)
|
104
|
+
|
105
|
+
$stderr.string.must_equal("")
|
106
|
+
$stdout.string.must_equal("")
|
107
|
+
end
|
86
108
|
end
|
87
109
|
|
88
110
|
it "finds gem executables" do
|
@@ -33,6 +33,16 @@ describe GemWrappers::Installer do
|
|
33
33
|
FileUtils.rm_rf(@test_path)
|
34
34
|
end
|
35
35
|
|
36
|
+
it "doe not prefix for .sh scripts" do
|
37
|
+
subject.instance_variable_set(:@executable, "/path/to/test.sh")
|
38
|
+
subject.executable_expanded.must_equal("/path/to/test.sh")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "adds ruby prefix for .rb scripts" do
|
42
|
+
subject.instance_variable_set(:@executable, "/path/to/test.rb")
|
43
|
+
subject.executable_expanded.must_equal("ruby /path/to/test.rb")
|
44
|
+
end
|
45
|
+
|
36
46
|
it "does create target dir" do
|
37
47
|
subject.instance_variable_set(:@wrappers_path, @test_path)
|
38
48
|
File.exist?(subject.wrappers_path).must_equal(false)
|
@@ -63,6 +73,62 @@ EXPECTED
|
|
63
73
|
end
|
64
74
|
end
|
65
75
|
|
76
|
+
it "creates shell script wrapper" do
|
77
|
+
subject.instance_variable_set(:@wrappers_path, @test_path)
|
78
|
+
script_path = File.join(subject.wrappers_path, "example", "test.sh")
|
79
|
+
FileUtils.mkdir_p(File.join(subject.wrappers_path, "example"))
|
80
|
+
File.open(script_path, "w") do |file|
|
81
|
+
file.write("echo test")
|
82
|
+
end
|
83
|
+
full_path = File.join(subject.wrappers_path, "test.sh")
|
84
|
+
File.exist?(full_path).must_equal(false)
|
85
|
+
subject.ensure
|
86
|
+
subject.install(script_path)
|
87
|
+
File.open(full_path, "r") do |file|
|
88
|
+
file.read.must_equal(<<-EXPECTED)
|
89
|
+
#!/usr/bin/env bash
|
90
|
+
|
91
|
+
if
|
92
|
+
[[ -s "/path/to/environment" ]]
|
93
|
+
then
|
94
|
+
source "/path/to/environment"
|
95
|
+
exec #{script_path} "$@"
|
96
|
+
else
|
97
|
+
echo "ERROR: Missing RVM environment file: '/path/to/environment'" >&2
|
98
|
+
exit 1
|
99
|
+
fi
|
100
|
+
EXPECTED
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
it "creates ruby script wrapper" do
|
105
|
+
subject.instance_variable_set(:@wrappers_path, @test_path)
|
106
|
+
script_path = File.join(subject.wrappers_path, "example", "test.rb")
|
107
|
+
FileUtils.mkdir_p(File.join(subject.wrappers_path, "example"))
|
108
|
+
File.open(script_path, "w") do |file|
|
109
|
+
file.write("puts :test")
|
110
|
+
end
|
111
|
+
full_path = File.join(subject.wrappers_path, "test.rb")
|
112
|
+
File.exist?(full_path).must_equal(false)
|
113
|
+
subject.ensure
|
114
|
+
subject.install(script_path)
|
115
|
+
File.open(full_path, "r") do |file|
|
116
|
+
file.read.must_equal(<<-EXPECTED)
|
117
|
+
#!/usr/bin/env bash
|
118
|
+
|
119
|
+
if
|
120
|
+
[[ -s "/path/to/environment" ]]
|
121
|
+
then
|
122
|
+
source "/path/to/environment"
|
123
|
+
exec ruby #{script_path} "$@"
|
124
|
+
else
|
125
|
+
echo "ERROR: Missing RVM environment file: '/path/to/environment'" >&2
|
126
|
+
exit 1
|
127
|
+
fi
|
128
|
+
EXPECTED
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
66
132
|
it "removes wrapper" do
|
67
133
|
subject.instance_variable_set(:@wrappers_path, @test_path)
|
68
134
|
full_path = File.join(subject.wrappers_path, "rake")
|
@@ -4,6 +4,10 @@ require 'gem-wrappers/version'
|
|
4
4
|
|
5
5
|
describe GemWrappers::Specification do
|
6
6
|
|
7
|
+
before do
|
8
|
+
GemWrappers::Specification.instance_variable_set(:@gem_wrappers_spec, nil)
|
9
|
+
end
|
10
|
+
|
7
11
|
it "finds specification" do
|
8
12
|
GemWrappers::Specification.find.name.must_equal("gem-wrappers")
|
9
13
|
end
|
@@ -12,4 +16,8 @@ describe GemWrappers::Specification do
|
|
12
16
|
GemWrappers::Specification.version.must_equal(GemWrappers::VERSION)
|
13
17
|
end
|
14
18
|
|
19
|
+
it "does not find imaginary gems" do
|
20
|
+
GemWrappers::Specification.find("imaginary-gem").must_equal(nil)
|
21
|
+
end
|
22
|
+
|
15
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem-wrappers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michal Papis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -48,6 +48,7 @@ extra_rdoc_files: []
|
|
48
48
|
files:
|
49
49
|
- .gitignore
|
50
50
|
- .travis.yml
|
51
|
+
- Changelog.md
|
51
52
|
- Gemfile
|
52
53
|
- LICENSE
|
53
54
|
- README.md
|
@@ -56,6 +57,7 @@ files:
|
|
56
57
|
- gem-wrappers.gemspec
|
57
58
|
- lib/gem-wrappers.rb
|
58
59
|
- lib/gem-wrappers/command.rb
|
60
|
+
- lib/gem-wrappers/command/file_exist.rb
|
59
61
|
- lib/gem-wrappers/environment.rb
|
60
62
|
- lib/gem-wrappers/installer.rb
|
61
63
|
- lib/gem-wrappers/specification.rb
|
@@ -87,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
89
|
version: '0'
|
88
90
|
requirements: []
|
89
91
|
rubyforge_project:
|
90
|
-
rubygems_version: 2.
|
92
|
+
rubygems_version: 2.1.11
|
91
93
|
signing_key:
|
92
94
|
specification_version: 4
|
93
95
|
summary: Create gem wrappers for easy use of gems in cron and other system locations.
|