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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA512:
3
- metadata.gz: 48cdb11322144423631158e936df29e14bc82b8f84f21ac86f4e7d1ff4e8385670f11e8ef281a31ae2e23e67230a5209174277bf9bc5f8022896e848733c84a8
4
- data.tar.gz: c345081a561bb037c618a9d589723e35bfa95442701024890a9269a6052a22afeaa7f7d4f97092af28194e82083ccd39b46adb4b6d00420e1d588026bf68c641
3
+ metadata.gz: 3ee86ce7a16e5713e54f5107c98e87a120c1b1538294ced359397a486fbebf440c3011f3a1824c22b17b4a01cedcd58a5a193ba85e5f9c388a6deec42b45a216
4
+ data.tar.gz: a2d79cfbf6daf92e5e458147fc6324e8b984804481c25b7a726eb64213db3186551df04caf2009eca954d7ef56b76c9bbe720ecdad8c099b14cf9c14b74937ac
5
5
  SHA1:
6
- metadata.gz: c63aa0209b7c2dab346841bfd12b7e5fa6e01804
7
- data.tar.gz: 515304c21b58a3535e6dba06229f95af1f4cc0d9
6
+ metadata.gz: d269e03a5d350449af2a2d0ea56d5b389a753bac
7
+ data.tar.gz: c9c42d1cdecfafe73f3bc71e812982de79ec18a8
data/.travis.yml CHANGED
@@ -1,4 +1,6 @@
1
1
  language: ruby
2
+ before_install:
3
+ - "if [[ $TRAVIS_RUBY_VERSION == 1.8.7 ]] ; then rvm rubygems latest-2.1 ; fi"
2
4
  rvm:
3
5
  - jruby
4
6
  - ruby-head
data/Changelog.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.2
4
+ date: 2013-12-31
5
+
6
+ - improved tests
7
+ - improved code to detect and set executable bits for the created wrapper, fix #3
8
+
3
9
  ## 1.2.1
4
10
  date: 2013-12-22
5
11
 
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
- GemWrappers::Installer.wrappers_path
37
+ installer.wrappers_path
34
38
  end
35
39
 
36
40
  def self.environment_file
37
- GemWrappers::Environment.file_name
41
+ environment.file_name
38
42
  end
39
43
 
40
44
  end
@@ -35,7 +35,7 @@ DOC
35
35
  when 'regenerate'
36
36
  execute_regenerate
37
37
  when FileExist
38
- execute_regenerate([File.expand_path(subcommand)]) # TODO: File.expand_path not tested!
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: #{GemWrappers.wrappers_path}"
47
- $stdout.puts "Environment file: #{GemWrappers.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
- GemWrappers.install(list)
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
- File.chmod(0755, file_name)
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
@@ -1,3 +1,3 @@
1
1
  module GemWrappers
2
- VERSION = "1.2.1"
2
+ VERSION = "1.2.2"
3
3
  end
@@ -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
- FileUtils.rm_rf(@test_path)
63
+ @file.close
64
+ @file.unlink
64
65
  end
65
66
 
66
- it "regenerates wrappers" do
67
- Gem.configuration[:wrappers_environment_file] = File.join(@test_path, "environment")
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
- 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"
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
@@ -127,6 +127,7 @@ else
127
127
  fi
128
128
  EXPECTED
129
129
  end
130
+ File.executable?(full_path).must_equal(true)
130
131
  end
131
132
 
132
133
  it "removes wrapper" do
@@ -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
- file = Tempfile.new('gem_dir')
8
- @test_path = file.path
9
- file.close
10
- file.unlink
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
- after do
14
- FileUtils.rm_rf(@test_path)
18
+ it "reads configured file" do
19
+ subject.environment_file.must_equal("/path/to/environment")
15
20
  end
16
21
 
17
- describe "configuration" do
18
- it "reads configured file" do
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
- Gem.configuration[:wrappers_path] = File.join(@test_path, "wrappers")
32
- Gem.configuration[:wrappers_environment_file] = File.join(@test_path, "environment")
33
- Gem.configuration[:wrappers_path_take] = 0
34
- GemWrappers.install(%w{rake test})
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
- Gem.configuration[:wrappers_path] = File.join(@test_path, "wrappers")
45
- Gem.configuration[:wrappers_environment_file] = File.join(@test_path, "environment")
46
- Gem.configuration[:wrappers_path_take] = 0
47
- GemWrappers.install(%w{rake})
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.1
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-22 00:00:00 Z
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