fixwhich 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/which.rb +83 -0
  3. metadata +66 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2bf5bcbfeed2196892a79510f181c5663d9872b4
4
+ data.tar.gz: fadbad659f8acaa1550ebb2413b2187bced8f8b3
5
+ SHA512:
6
+ metadata.gz: f3b5427f74bec87105f5b6a8e10e6cd55034323b27643f3b84457d9bc1f409227dbd59de8a261e4421dce110d594b5fba9fdf959e424e0240bc3aa7d73b893c7
7
+ data.tar.gz: 50aca8671cd60a81d890151f7d2eb587f178d137eac63ef87d4016ba00a7743b11edd11e9cb6f63c481434826feaaa97b4cba4214e119c2da94c4ad627a809ae
data/lib/which.rb ADDED
@@ -0,0 +1,83 @@
1
+ begin
2
+ require 'rubygems'
3
+ rescue LoadError => e
4
+ end
5
+
6
+ require 'pathname2'
7
+
8
+ #
9
+ # Skeleton module for the 'which' routine.
10
+ #
11
+ # Ideally, one would do this in their code to import the "which" call
12
+ # directly into their current namespace:
13
+ #
14
+ # require 'which'
15
+ # include Which
16
+ # # do something with which()
17
+ #
18
+ #
19
+ # It is recommended that you look at the documentation for the which()
20
+ # call directly for specific usage.
21
+ #
22
+ #--
23
+ #
24
+ # The compilation of software known as which.rb is distributed under the
25
+ # following terms:
26
+ # Copyright (C) 2005-2006 Erik Hollensbe. All rights reserved.
27
+ #
28
+ # Redistribution and use in source form, with or without
29
+ # modification, are permitted provided that the following conditions
30
+ # are met:
31
+ # 1. Redistributions of source code must retain the above copyright
32
+ # notice, this list of conditions and the following disclaimer.
33
+ #
34
+ # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
35
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37
+ # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
38
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40
+ # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41
+ # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42
+ # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43
+ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44
+ # SUCH DAMAGE.
45
+ #
46
+ #++
47
+
48
+ module Which
49
+
50
+ #
51
+ # Searches the path, or a provided path with given separators
52
+ # (path_sep, commonly ":") and a separator for directories (dir_sep,
53
+ # commonly "/" or "\\" on windows), will return all of the places
54
+ # that filename occurs. `filename' is included as a part of the
55
+ # output.
56
+ #
57
+ # Note that the filename must both exist in the path _and_ be
58
+ # executable for it to appear in the return value.
59
+ #
60
+ # Those familiar with the which(1) utility from UNIX will notice the
61
+ # similarities.
62
+ #
63
+
64
+ def which(filename, path=ENV["PATH"], path_sep=File::PATH_SEPARATOR, dir_sep=File::SEPARATOR)
65
+ dirs = path.split(/#{path_sep}/)
66
+
67
+ locations = []
68
+
69
+ dirs.each do |dir|
70
+ newfile = "#{dir}#{dir_sep}#{filename}"
71
+ # strip any extra dir separators
72
+ newfile.gsub!(/#{dir_sep}{2,}/, "#{dir_sep}")
73
+ p = Pathname.new(newfile)
74
+ if p.exist? and p.executable?
75
+ locations.push(newfile)
76
+ end
77
+ end
78
+
79
+ return locations
80
+ end
81
+
82
+ module_function :which
83
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fixwhich
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Erik Hollensbe
8
+ - Richard Smith-Unna
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-12-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pathname2
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.4'
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.4.4
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - "~>"
29
+ - !ruby/object:Gem::Version
30
+ version: '1.4'
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.4.4
34
+ description:
35
+ email: rds45@cam.ac.uk
36
+ executables: []
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - lib/which.rb
41
+ homepage: http://blahah.net
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.2.2
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Just the which gem with file permissions fixed
66
+ test_files: []