gem-wrappers 1.3.2 → 1.4.0

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
- ---
2
- SHA1:
3
- data.tar.gz: 8760f42ee3404a92db5666a4c13f651ea101ba65
4
- metadata.gz: 3042f776a429469c017f523557261b0a453c6204
5
- SHA512:
6
- data.tar.gz: c90e21bcd1906252f3948f79691ecf9298eebbb6a28f620fa67b66e3b603a626d2e9635619d8389bf3c921e0651c898ae904077a6c2aa95b91c0863ebf26b7d8
7
- metadata.gz: 5c32a9e16c6d3622151b46ef54fbbd0bc8e7553644e2961f32b8828322dfc4381dd6f39e79c05187defca3d4f07c533067dcea19a6e09d281d5396b455229cd1
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 86a58106c9a11be5ed1d3a1e7d88f2d7418b3752
4
+ data.tar.gz: 6df162cbfbe63de825949ad7b4138138a27f63da
5
+ SHA512:
6
+ metadata.gz: 90e94c807854494b09eb8008f17dc576dbb79effe2f3c437d1269427482be4569f29312631a8b36b7253291759ab7d2adba375118de4ac9e61fc6edeff33efb3
7
+ data.tar.gz: 52da011fcb220741b5d40ee5300963362ff97202aa6ad71f1b1fcd8474c25f16b4953c773277ff410a41ca5c4a2724bc418574e12024ed64bd05bde4ffc6f10c
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.4.0
4
+ date: 2017-09-22
5
+
6
+ - add option to show full path to single file
7
+ - list actual list of generated wrappers in show
8
+
3
9
  ## 1.3.2
4
10
  date: 2017-09-10
5
11
 
data/README.md CHANGED
@@ -53,7 +53,7 @@ gem install unicorn
53
53
  The `unicorn` wrapper is located in `$GEM_HOME/wrappers`:
54
54
 
55
55
  ```bash
56
- ls `gem env gemhome`/wrappers/unicorn
56
+ gem wrappers show unicorn
57
57
  ```
58
58
 
59
59
  ```ssh
@@ -91,7 +91,7 @@ export GEM_PATH="<%= gem_path.join(":") %>"
91
91
  export GEM_HOME="<%= gem_home %>"
92
92
  ```
93
93
 
94
- The path elements are calculated using this algorithm:
94
+ The `path` elements are calculated using this algorithm:
95
95
 
96
96
  ```ruby
97
97
  ENV['PATH'].split(":").take(Gem.path.size + path_take)
@@ -1,7 +1,10 @@
1
+ require 'rbconfig'
1
2
  require 'gem-wrappers/environment'
2
3
  require 'gem-wrappers/installer'
3
4
 
4
5
  module GemWrappers
6
+ class Exception < Gem::Exception ; end
7
+ class NoWrapper < Exception ; end
5
8
 
6
9
  def self.environment
7
10
  @environment ||= GemWrappers::Environment.new
@@ -36,18 +39,42 @@ module GemWrappers
36
39
  installer.wrappers_path
37
40
  end
38
41
 
42
+ def self.wrapper_path(exe)
43
+ file = File.join(wrappers_path, exe)
44
+ if executable?(file)
45
+ file
46
+ else
47
+ raise GemWrappers::NoWrapper, "No wrapper: #{file}"
48
+ end
49
+ end
50
+
51
+ def self.installed_wrappers
52
+ executables_in_directory(wrappers_path).sort.uniq
53
+ end
54
+
55
+ def self.gems_executables
56
+ # do not use map(&:...) - for ruby 1.8.6 compatibility
57
+ @executables ||= GemWrappers::Specification.installed_gems.map{|gem| gem.executables }.inject{|sum, n| sum + n }.uniq || []
58
+ end
59
+
39
60
  def self.environment_file
40
61
  environment.file_name
41
62
  end
42
63
 
43
- private
44
-
45
64
  def self.ruby_executables
46
- bindir = RbConfig::CONFIG["bindir"].sub(/\/+\z/, '')
47
- Dir.entries(bindir).select do |file|
48
- path = "#{bindir}/#{file}"
49
- !File.directory?(path) && File.executable?(path)
65
+ executables_in_directory(RbConfig::CONFIG["bindir"].sub(/\/+\z/, ''))
66
+ end
67
+ private_class_method :ruby_executables
68
+
69
+ def self.executables_in_directory(dir)
70
+ Dir.entries(dir).select do |file|
71
+ executable?(File.join(dir, file))
50
72
  end
51
73
  end
74
+ private_class_method :executables_in_directory
52
75
 
76
+ def self.executable?(path)
77
+ !File.directory?(path) && File.executable?(path)
78
+ end
79
+ private_class_method :executable?
53
80
  end
@@ -32,7 +32,7 @@ DOC
32
32
  subcommand = args.shift || ''
33
33
  case subcommand
34
34
  when '', 'show'
35
- execute_show(args)
35
+ args.empty? ? execute_show : execute_show_path(args.first)
36
36
  when 'regenerate'
37
37
  execute_regenerate(args)
38
38
  when FileExist
@@ -42,8 +42,12 @@ DOC
42
42
  end
43
43
  end
44
44
 
45
- def execute_show(list = [])
46
- list = executables if list.empty?
45
+ def execute_show_path(exe)
46
+ $stdout.puts gem_wrappers.wrapper_path(exe)
47
+ end
48
+
49
+ def execute_show
50
+ list = gem_wrappers.installed_wrappers
47
51
  $stdout.puts description
48
52
  $stdout.puts " Wrappers path: #{gem_wrappers.wrappers_path}"
49
53
  $stdout.puts "Environment file: #{gem_wrappers.environment_file}"
@@ -57,7 +61,7 @@ DOC
57
61
  end
58
62
 
59
63
  def execute_regenerate(list = [])
60
- list = executables if list.empty?
64
+ list = gem_wrappers.gems_executables if list.empty?
61
65
  execute_show(list) if ENV['GEM_WRAPPERS_DEBUG']
62
66
  gem_wrappers.install(list)
63
67
  end
@@ -67,11 +71,6 @@ private
67
71
  def gem_wrappers
68
72
  @gem_wrappers ||= GemWrappers
69
73
  end
70
-
71
- def executables
72
- # do not use map(&:...) - for ruby 1.8.6 compatibility
73
- @executables ||= GemWrappers::Specification.installed_gems.map{|gem| gem.executables }.inject{|sum, n| sum + n } || []
74
- end
75
74
  end
76
75
 
77
76
  require 'gem-wrappers/command/file_exist'
@@ -1,3 +1,3 @@
1
1
  module GemWrappers
2
- VERSION = "1.3.2"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'test_helper'
2
+ require 'pathname'
2
3
  require 'tempfile'
3
4
  require 'gem-wrappers/command'
4
5
  require 'gem-wrappers/fakes'
@@ -8,9 +9,11 @@ describe WrappersCommand do
8
9
  WrappersCommand.new
9
10
  end
10
11
 
12
+ let(:gems) { %w[rake ruby] }
13
+
11
14
  before do
12
- @fake_installer = GemWrappers::Fake.new
13
- subject.instance_variable_set(:@gem_wrappers, @fake_installer)
15
+ @fake_wrappers = GemWrappers::Fake.new(gems)
16
+ subject.instance_variable_set(:@gem_wrappers, @fake_wrappers)
14
17
  $stdout = StringIO.new
15
18
  $stderr = StringIO.new
16
19
  end
@@ -36,23 +39,30 @@ describe WrappersCommand do
36
39
  end
37
40
 
38
41
  it "does show" do
39
- subject.options[:args] = ["show", "rake"]
42
+ subject.options[:args] = ["show"]
40
43
  subject.execute
41
44
 
42
45
  $stderr.string.must_equal("")
43
- $stdout.string.must_equal(<<-EXPECTED)
44
- #{subject.description.strip}
46
+ $stdout.string.must_match(%r{\
47
+ #{Regexp.escape(subject.description.strip)}
45
48
  Wrappers path: /path/to/wrappers
46
49
  Environment file: /path/to/environment
47
- Executables: rake
48
- EXPECTED
50
+ Executables: rake, ruby
51
+ })
52
+ end
53
+
54
+ it "does show rake" do
55
+ subject.options[:args] = ["show", "rake"]
56
+ subject.execute
57
+
58
+ $stderr.string.must_equal("")
59
+ $stdout.string.must_equal("/path/to/wrappers/rake\n")
49
60
  end
50
61
 
51
62
  it "regenerates wrappers" do
52
- subject.instance_variable_set(:@executables, %w{rake})
53
- subject.options[:args] = ['regenerate']
63
+ subject.options[:args] = %w{regenerate rake}
54
64
  subject.execute
55
- @fake_installer.executables.must_equal(%w{rake})
65
+ @fake_wrappers.executables.must_equal(%w{rake})
56
66
  end
57
67
 
58
68
  describe "script wrappers" do
@@ -68,20 +78,15 @@ EXPECTED
68
78
  it "generates script wrapper full path" do
69
79
  subject.options[:args] = [@file.path]
70
80
  subject.execute
71
- @fake_installer.executables.must_equal([@file.path])
81
+ @fake_wrappers.executables.must_equal([@file.path])
72
82
  end
73
83
 
74
84
  it "generates script wrapper relative" do
75
85
  Dir.chdir(File.dirname(@file.path)) do
76
86
  subject.options[:args] = [File.basename(@file.path)]
77
87
  subject.execute
78
- @fake_installer.executables.must_equal([Pathname.new(@file.path).realpath.to_s])
88
+ @fake_wrappers.executables.must_equal([Pathname.new(@file.path).realpath.to_s])
79
89
  end
80
90
  end
81
91
  end
82
-
83
- it "finds gem executables" do
84
- subject.send(:executables).must_include('rake')
85
- end
86
-
87
92
  end
@@ -34,7 +34,8 @@ module GemWrappers
34
34
  end
35
35
  end
36
36
  class Fake
37
- def initialize
37
+ def initialize(gems)
38
+ @gems = gems
38
39
  @executables = []
39
40
  end
40
41
  def install(executables)
@@ -52,5 +53,19 @@ module GemWrappers
52
53
  def wrappers_path
53
54
  "/path/to/wrappers"
54
55
  end
56
+ def wrapper_path(exe)
57
+ file = File.join(wrappers_path, exe)
58
+ if @gems.include?(exe)
59
+ file
60
+ else
61
+ raise GemWrappers::NoWrapper, "No wrapper: #{file}"
62
+ end
63
+ end
64
+ def installed_wrappers
65
+ @gems
66
+ end
67
+ def gems_executables
68
+ @gems
69
+ end
55
70
  end
56
71
  end
@@ -72,7 +72,7 @@ GEMRC
72
72
  FileUtils.rm_rf(@test_path)
73
73
  end
74
74
 
75
- it "installas wrappers" do
75
+ it "installas wrappers and finds wrapper path" do
76
76
  File.exist?(@rake_wrapper).must_equal(false)
77
77
  subject.install(%w{rake})
78
78
  File.exist?(@rake_wrapper ).must_equal(true)
@@ -87,6 +87,38 @@ GEMRC
87
87
  subject.uninstall(%w{rake})
88
88
  File.exist?(@rake_wrapper ).must_equal(false)
89
89
  end
90
+
91
+ it "finds gem executables" do
92
+ subject.send(:gems_executables).must_include("rake")
93
+ end
94
+
95
+ it "shows rake in executables" do
96
+ Dir.mkdir(@wrappers_path)
97
+ File.open(@rake_wrapper, "w") { |f| f.write("") }
98
+ File.chmod(0755, @rake_wrapper)
99
+ subject.installed_wrappers.must_equal(["rake"])
100
+ end
101
+
102
+ it "finds rake path" do
103
+ Dir.mkdir(@wrappers_path)
104
+ File.open(@rake_wrapper, "w") { |f| f.write("") }
105
+ File.chmod(0755, @rake_wrapper)
106
+ subject.wrapper_path("rake").must_equal(@rake_wrapper)
107
+ end
108
+
109
+ it "doesn't find rake path when not executable" do
110
+ Dir.mkdir(@wrappers_path)
111
+ File.open(@rake_wrapper, "w") { |f| f.write("") }
112
+ proc {
113
+ subject.wrapper_path("rak2e")
114
+ }.must_raise(GemWrappers::NoWrapper)
115
+ end
116
+
117
+ it "doesn't find rake path when missing" do
118
+ proc {
119
+ subject.wrapper_path("rak2e")
120
+ }.must_raise(GemWrappers::NoWrapper)
121
+ end
90
122
  end
91
123
 
92
124
  end
metadata CHANGED
@@ -1,46 +1,51 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: gem-wrappers
3
- version: !ruby/object:Gem::Version
4
- version: 1.3.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.0
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Michal Papis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2017-09-10 00:00:00 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
11
+ date: 2017-09-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
15
14
  name: rake
16
- prerelease: false
17
- requirement: &id001 !ruby/object:Gem::Requirement
18
- requirements:
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
19
17
  - - <
20
- - !ruby/object:Gem::Version
21
- version: "11"
18
+ - !ruby/object:Gem::Version
19
+ version: '11'
22
20
  type: :development
23
- version_requirements: *id001
24
- - !ruby/object:Gem::Dependency
25
- name: minitest
26
21
  prerelease: false
27
- requirement: &id002 !ruby/object:Gem::Requirement
28
- requirements:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - <
25
+ - !ruby/object:Gem::Version
26
+ version: '11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
29
31
  - - <
30
- - !ruby/object:Gem::Version
31
- version: "6"
32
+ - !ruby/object:Gem::Version
33
+ version: '6'
32
34
  type: :development
33
- version_requirements: *id002
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - <
39
+ - !ruby/object:Gem::Version
40
+ version: '6'
34
41
  description:
35
- email:
42
+ email:
36
43
  - mpapis@gmail.com
37
44
  executables: []
38
-
39
- extensions:
45
+ extensions:
40
46
  - ext/wrapper_generator/extconf.rb
41
47
  extra_rdoc_files: []
42
-
43
- files:
48
+ files:
44
49
  - .gitignore
45
50
  - .travis.yml
46
51
  - Changelog.md
@@ -66,32 +71,30 @@ files:
66
71
  - test/gem-wrappers_test.rb
67
72
  - test/test_helper.rb
68
73
  homepage: https://github.com/rvm/gem-wrappers
69
- licenses:
74
+ licenses:
70
75
  - Apache 2.0
71
76
  metadata: {}
72
-
73
77
  post_install_message:
74
78
  rdoc_options: []
75
-
76
- require_paths:
79
+ require_paths:
77
80
  - lib
78
- required_ruby_version: !ruby/object:Gem::Requirement
79
- requirements:
80
- - &id003
81
- - ">="
82
- - !ruby/object:Gem::Version
83
- version: "0"
84
- required_rubygems_version: !ruby/object:Gem::Requirement
85
- requirements:
86
- - *id003
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
87
91
  requirements: []
88
-
89
92
  rubyforge_project:
90
- rubygems_version: 2.0.17
93
+ rubygems_version: 2.6.12
91
94
  signing_key:
92
95
  specification_version: 4
93
96
  summary: Create gem wrappers for easy use of gems in cron and other system locations.
94
- test_files:
97
+ test_files:
95
98
  - test/gem-wrappers/command_test.rb
96
99
  - test/gem-wrappers/environment_test.rb
97
100
  - test/gem-wrappers/fakes.rb