gem-wrappers 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/Changelog.md +6 -0
- data/README.md +29 -0
- data/lib/gem-wrappers.rb +10 -6
- data/lib/gem-wrappers/command.rb +8 -4
- data/lib/gem-wrappers/installer.rb +7 -1
- data/lib/gem-wrappers/version.rb +1 -1
- data/test/gem-wrappers/command_test.rb +21 -49
- data/test/gem-wrappers/fakes.rb +56 -0
- data/test/gem-wrappers/installer_test.rb +1 -0
- data/test/gem-wrappers_test.rb +21 -34
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA512:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ee86ce7a16e5713e54f5107c98e87a120c1b1538294ced359397a486fbebf440c3011f3a1824c22b17b4a01cedcd58a5a193ba85e5f9c388a6deec42b45a216
|
4
|
+
data.tar.gz: a2d79cfbf6daf92e5e458147fc6324e8b984804481c25b7a726eb64213db3186551df04caf2009eca954d7ef56b76c9bbe720ecdad8c099b14cf9c14b74937ac
|
5
5
|
SHA1:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d269e03a5d350449af2a2d0ea56d5b389a753bac
|
7
|
+
data.tar.gz: c9c42d1cdecfafe73f3bc71e812982de79ec18a8
|
data/.travis.yml
CHANGED
data/Changelog.md
CHANGED
data/README.md
CHANGED
@@ -9,6 +9,14 @@
|
|
9
9
|
|
10
10
|
Create gem wrappers for easy use of gems in cron and other system locations.
|
11
11
|
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
This gem should be available in RVM `1.25+`, to install manually:
|
15
|
+
|
16
|
+
```bash
|
17
|
+
gem install gem-wrappers
|
18
|
+
```
|
19
|
+
|
12
20
|
## Configuration / Defaults
|
13
21
|
|
14
22
|
In `~/.gemrc` you can overwrite this defaults:
|
@@ -33,6 +41,27 @@ gem wrappers regenerate
|
|
33
41
|
|
34
42
|
wrappers will be generated in `$GEM_HOME/wrappers/`.
|
35
43
|
|
44
|
+
### Example
|
45
|
+
|
46
|
+
Install popular http server `unicorn`:
|
47
|
+
|
48
|
+
```bash
|
49
|
+
gem install gem-wrappers # assuming it was not installed already
|
50
|
+
gem install unicorn
|
51
|
+
```
|
52
|
+
|
53
|
+
The `unicorn` wrapper is located in `$GEM_HOME/wrappers`:
|
54
|
+
|
55
|
+
```bash
|
56
|
+
ls `gem env gemhome`/wrappers/unicorn
|
57
|
+
```
|
58
|
+
|
59
|
+
```ssh
|
60
|
+
/home/mpapis/.rvm/gems/ruby-2.1.0-preview2/wrappers/unicorn
|
61
|
+
```
|
62
|
+
|
63
|
+
This script will make sure proper environment is available.
|
64
|
+
|
36
65
|
## Generating scripts wrappers
|
37
66
|
|
38
67
|
It is possible to generate wrappers for custom scripts:
|
data/lib/gem-wrappers.rb
CHANGED
@@ -3,10 +3,16 @@ require 'gem-wrappers/installer'
|
|
3
3
|
|
4
4
|
module GemWrappers
|
5
5
|
|
6
|
+
def self.environment
|
7
|
+
@environment ||= GemWrappers::Environment.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.installer
|
11
|
+
@installer ||= GemWrappers::Installer.new(@environment.file_name)
|
12
|
+
end
|
13
|
+
|
6
14
|
def self.install(executables)
|
7
|
-
environment = GemWrappers::Environment.new
|
8
15
|
environment.ensure
|
9
|
-
installer = GemWrappers::Installer.new(environment.file_name)
|
10
16
|
installer.ensure
|
11
17
|
|
12
18
|
# gem executables
|
@@ -21,8 +27,6 @@ module GemWrappers
|
|
21
27
|
end
|
22
28
|
|
23
29
|
def self.uninstall(executables)
|
24
|
-
installer = GemWrappers::Installer.new
|
25
|
-
|
26
30
|
# gem executables
|
27
31
|
executables.each do |executable|
|
28
32
|
installer.uninstall(executable)
|
@@ -30,11 +34,11 @@ module GemWrappers
|
|
30
34
|
end
|
31
35
|
|
32
36
|
def self.wrappers_path
|
33
|
-
|
37
|
+
installer.wrappers_path
|
34
38
|
end
|
35
39
|
|
36
40
|
def self.environment_file
|
37
|
-
|
41
|
+
environment.file_name
|
38
42
|
end
|
39
43
|
|
40
44
|
end
|
data/lib/gem-wrappers/command.rb
CHANGED
@@ -35,7 +35,7 @@ DOC
|
|
35
35
|
when 'regenerate'
|
36
36
|
execute_regenerate
|
37
37
|
when FileExist
|
38
|
-
execute_regenerate([File.expand_path(subcommand)])
|
38
|
+
execute_regenerate([File.expand_path(subcommand)])
|
39
39
|
else
|
40
40
|
execute_unknown subcommand
|
41
41
|
end
|
@@ -43,8 +43,8 @@ DOC
|
|
43
43
|
|
44
44
|
def execute_show
|
45
45
|
$stdout.puts description
|
46
|
-
$stdout.puts " Wrappers path: #{
|
47
|
-
$stdout.puts "Environment file: #{
|
46
|
+
$stdout.puts " Wrappers path: #{gem_wrappers.wrappers_path}"
|
47
|
+
$stdout.puts "Environment file: #{gem_wrappers.environment_file}"
|
48
48
|
end
|
49
49
|
|
50
50
|
def execute_unknown(subcommand)
|
@@ -54,11 +54,15 @@ DOC
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def execute_regenerate(list = executables)
|
57
|
-
|
57
|
+
gem_wrappers.install(list)
|
58
58
|
end
|
59
59
|
|
60
60
|
private
|
61
61
|
|
62
|
+
def gem_wrappers
|
63
|
+
@gem_wrappers ||= GemWrappers
|
64
|
+
end
|
65
|
+
|
62
66
|
def executables
|
63
67
|
# do not use map(&:...) - for ruby 1.8.6 compatibility
|
64
68
|
@executables ||= GemWrappers::Specification.installed_gems.map{|gem| gem.executables }.inject{|sum, n| sum + n } || []
|
@@ -36,7 +36,7 @@ module GemWrappers
|
|
36
36
|
File.open(file_name, 'w') do |file|
|
37
37
|
file.write(content)
|
38
38
|
end
|
39
|
-
|
39
|
+
file_set_executable(file_name)
|
40
40
|
end
|
41
41
|
|
42
42
|
def executable_expanded
|
@@ -62,5 +62,11 @@ fi
|
|
62
62
|
TEMPLATE
|
63
63
|
end
|
64
64
|
|
65
|
+
private
|
66
|
+
def file_set_executable(file_name)
|
67
|
+
stat = File.stat(file_name)
|
68
|
+
File.chmod(stat.mode|0111, file_name) unless stat.mode&0111 == 0111
|
69
|
+
end
|
70
|
+
|
65
71
|
end
|
66
72
|
end
|
data/lib/gem-wrappers/version.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
require 'tempfile'
|
3
3
|
require 'gem-wrappers/command'
|
4
|
+
require 'gem-wrappers/fakes'
|
4
5
|
|
5
6
|
describe WrappersCommand do
|
6
7
|
subject do
|
@@ -8,6 +9,8 @@ describe WrappersCommand do
|
|
8
9
|
end
|
9
10
|
|
10
11
|
before do
|
12
|
+
@fake_installer = GemWrappers::Fake.new
|
13
|
+
subject.instance_variable_set(:@gem_wrappers, @fake_installer)
|
11
14
|
$stdout = StringIO.new
|
12
15
|
$stderr = StringIO.new
|
13
16
|
end
|
@@ -33,15 +36,9 @@ describe WrappersCommand do
|
|
33
36
|
end
|
34
37
|
|
35
38
|
it "does show" do
|
36
|
-
Gem.configuration[:wrappers_environment_file] = "/path/to/environment"
|
37
|
-
Gem.configuration[:wrappers_path] = "/path/to/wrappers"
|
38
|
-
|
39
39
|
subject.options[:args] = []
|
40
40
|
subject.execute
|
41
41
|
|
42
|
-
Gem.configuration[:wrappers_environment_file] = nil
|
43
|
-
Gem.configuration[:wrappers_path] = nil
|
44
|
-
|
45
42
|
$stderr.string.must_equal("")
|
46
43
|
$stdout.string.must_equal(<<-EXPECTED)
|
47
44
|
#{subject.description.strip}
|
@@ -50,60 +47,35 @@ Environment file: /path/to/environment
|
|
50
47
|
EXPECTED
|
51
48
|
end
|
52
49
|
|
50
|
+
it "regenerates wrappers" do
|
51
|
+
subject.instance_variable_set(:@executables, %w{rake})
|
52
|
+
subject.options[:args] = ['regenerate']
|
53
|
+
subject.execute
|
54
|
+
@fake_installer.executables.must_equal(%w{rake})
|
55
|
+
end
|
53
56
|
|
54
|
-
describe "wrappers" do
|
57
|
+
describe "script wrappers" do
|
55
58
|
before do
|
56
|
-
file = Tempfile.new('command-wrappers')
|
57
|
-
@test_path = file.path
|
58
|
-
file.close
|
59
|
-
file.unlink
|
59
|
+
@file = Tempfile.new('command-wrappers')
|
60
60
|
end
|
61
61
|
|
62
62
|
after do
|
63
|
-
|
63
|
+
@file.close
|
64
|
+
@file.unlink
|
64
65
|
end
|
65
66
|
|
66
|
-
it "
|
67
|
-
|
68
|
-
Gem.configuration[:wrappers_path] = File.join(@test_path, "wrappers")
|
69
|
-
|
70
|
-
subject.instance_variable_set(:@executables, %w{rake})
|
71
|
-
subject.options[:args] = ['regenerate']
|
67
|
+
it "generates script wrapper full path" do
|
68
|
+
subject.options[:args] = [@file.path]
|
72
69
|
subject.execute
|
73
|
-
|
74
|
-
Gem.configuration[:wrappers_environment_file] = nil
|
75
|
-
Gem.configuration[:wrappers_path] = nil
|
76
|
-
|
77
|
-
File.exist?(File.join(@test_path, "environment")).must_equal(true)
|
78
|
-
File.exist?(File.join(@test_path, "wrappers", "gem")).must_equal(true)
|
79
|
-
File.exist?(File.join(@test_path, "wrappers", "rake")).must_equal(true)
|
80
|
-
File.exist?(File.join(@test_path, "wrappers", "ruby")).must_equal(true)
|
81
|
-
File.exist?(File.join(@test_path, "wrappers", "test")).must_equal(false)
|
82
|
-
|
83
|
-
$stderr.string.must_equal("")
|
84
|
-
$stdout.string.must_equal("")
|
70
|
+
@fake_installer.executables.must_equal([@file.path])
|
85
71
|
end
|
86
72
|
|
87
|
-
it "generates script wrapper" do
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
file.
|
73
|
+
it "generates script wrapper relative" do
|
74
|
+
Dir.chdir(File.dirname(@file.path)) do
|
75
|
+
subject.options[:args] = [File.basename(@file.path)]
|
76
|
+
subject.execute
|
77
|
+
@fake_installer.executables.must_equal([@file.path])
|
92
78
|
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
79
|
end
|
108
80
|
end
|
109
81
|
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module GemWrappers
|
2
|
+
class FakeInstaller
|
3
|
+
def initialize
|
4
|
+
@executables = []
|
5
|
+
end
|
6
|
+
def install(executable)
|
7
|
+
@executables << executable
|
8
|
+
end
|
9
|
+
def uninstall(executable)
|
10
|
+
@executables.delete(executable)
|
11
|
+
end
|
12
|
+
def executables
|
13
|
+
@executables
|
14
|
+
end
|
15
|
+
def ensure
|
16
|
+
@ensure = true
|
17
|
+
end
|
18
|
+
def ensure?
|
19
|
+
@ensure
|
20
|
+
end
|
21
|
+
def wrappers_path
|
22
|
+
"/path/to/wrappers"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
class FakeEnvironment
|
26
|
+
def ensure
|
27
|
+
@ensure = true
|
28
|
+
end
|
29
|
+
def ensure?
|
30
|
+
@ensure
|
31
|
+
end
|
32
|
+
def file_name
|
33
|
+
"/path/to/environment"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
class Fake
|
37
|
+
def initialize
|
38
|
+
@executables = []
|
39
|
+
end
|
40
|
+
def install(executables)
|
41
|
+
@executables += executables
|
42
|
+
end
|
43
|
+
def uninstall(executables)
|
44
|
+
@executables -= executables
|
45
|
+
end
|
46
|
+
def executables
|
47
|
+
@executables
|
48
|
+
end
|
49
|
+
def environment_file
|
50
|
+
"/path/to/environment"
|
51
|
+
end
|
52
|
+
def wrappers_path
|
53
|
+
"/path/to/wrappers"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/test/gem-wrappers_test.rb
CHANGED
@@ -1,53 +1,40 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
require 'tempfile'
|
3
3
|
require 'gem-wrappers'
|
4
|
+
require 'gem-wrappers/fakes'
|
4
5
|
|
5
6
|
describe GemWrappers do
|
7
|
+
subject do
|
8
|
+
GemWrappers
|
9
|
+
end
|
10
|
+
|
6
11
|
before do
|
7
|
-
|
8
|
-
@
|
9
|
-
|
10
|
-
|
12
|
+
@fake_installer = GemWrappers::FakeInstaller.new
|
13
|
+
@fake_envvironment = GemWrappers::FakeEnvironment.new
|
14
|
+
subject.instance_variable_set(:@installer, @fake_installer)
|
15
|
+
subject.instance_variable_set(:@environment, @fake_envvironment)
|
11
16
|
end
|
12
17
|
|
13
|
-
|
14
|
-
|
18
|
+
it "reads configured file" do
|
19
|
+
subject.environment_file.must_equal("/path/to/environment")
|
15
20
|
end
|
16
21
|
|
17
|
-
|
18
|
-
|
19
|
-
Gem.configuration[:wrappers_environment_file] = "/path/to/environment"
|
20
|
-
GemWrappers.environment_file.must_equal("/path/to/environment")
|
21
|
-
Gem.configuration[:wrappers_environment_file] = nil
|
22
|
-
end
|
23
|
-
it "reads configured file" do
|
24
|
-
Gem.configuration[:wrappers_path] = "/path/to/wrappers"
|
25
|
-
GemWrappers.wrappers_path.must_equal("/path/to/wrappers")
|
26
|
-
Gem.configuration[:wrappers_path] = nil
|
27
|
-
end
|
22
|
+
it "reads configured file" do
|
23
|
+
subject.wrappers_path.must_equal("/path/to/wrappers")
|
28
24
|
end
|
29
25
|
|
30
26
|
it "does create environment and wrapper" do
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
File.exist?(File.join(@test_path, "environment")).must_equal(true)
|
36
|
-
File.exist?(File.join(@test_path, "wrappers", "gem")).must_equal(true)
|
37
|
-
File.exist?(File.join(@test_path, "wrappers", "rake")).must_equal(true)
|
38
|
-
File.exist?(File.join(@test_path, "wrappers", "ruby")).must_equal(true)
|
39
|
-
File.exist?(File.join(@test_path, "wrappers", "test")).must_equal(true)
|
40
|
-
File.exist?(File.join(@test_path, "wrappers", "other")).must_equal(false)
|
27
|
+
subject.install(%w{rake test})
|
28
|
+
@fake_envvironment.ensure?.must_equal(true)
|
29
|
+
@fake_installer.ensure?.must_equal(true)
|
30
|
+
@fake_installer.executables.must_equal(%w{rake test ruby gem erb irb ri rdoc testrb})
|
41
31
|
end
|
42
32
|
|
43
33
|
it "does remove wrapper" do
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
File.exist?(File.join(@test_path, "wrappers", "rake")).must_equal(true)
|
49
|
-
GemWrappers.uninstall(%w{rake})
|
50
|
-
File.exist?(File.join(@test_path, "wrappers", "rake")).must_equal(false)
|
34
|
+
subject.install(%w{rake})
|
35
|
+
@fake_installer.executables.must_equal(%w{rake ruby gem erb irb ri rdoc testrb})
|
36
|
+
subject.uninstall(%w{rake})
|
37
|
+
@fake_installer.executables.must_equal(%w{ruby gem erb irb ri rdoc testrb})
|
51
38
|
end
|
52
39
|
|
53
40
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem-wrappers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michal Papis
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2013-12-
|
12
|
+
date: 2013-12-31 00:00:00 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- lib/rubygems_plugin.rb
|
60
60
|
- test/gem-wrappers/command_test.rb
|
61
61
|
- test/gem-wrappers/environment_test.rb
|
62
|
+
- test/gem-wrappers/fakes.rb
|
62
63
|
- test/gem-wrappers/installer_test.rb
|
63
64
|
- test/gem-wrappers/specification_and_version_test.rb
|
64
65
|
- test/gem-wrappers_test.rb
|
@@ -89,6 +90,7 @@ summary: Create gem wrappers for easy use of gems in cron and other system locat
|
|
89
90
|
test_files:
|
90
91
|
- test/gem-wrappers/command_test.rb
|
91
92
|
- test/gem-wrappers/environment_test.rb
|
93
|
+
- test/gem-wrappers/fakes.rb
|
92
94
|
- test/gem-wrappers/installer_test.rb
|
93
95
|
- test/gem-wrappers/specification_and_version_test.rb
|
94
96
|
- test/gem-wrappers_test.rb
|