macaddr-steakknife 1.8.1 → 1.8.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
  SHA1:
3
- metadata.gz: 9f906059c5f5373bab2e63c44aad284b22a57754
4
- data.tar.gz: a3fd15a47f7c28d8215453b93505f6a8475ed6fa
3
+ metadata.gz: 89fda8a6bf84dab6f3ac7cfd58f9705caea4db4a
4
+ data.tar.gz: b3c43c3f7a542a55becb6808940f834b3c1e4339
5
5
  SHA512:
6
- metadata.gz: cd4a9f0efab8588c161f0fa3920a564e6cfd9f44298583e3b4ad9a50c70ce7e535559aed97eea33d1ad44fe4c2885037885a0b9a5b9747d536a3d2c6c0b2d8c0
7
- data.tar.gz: 2aa1f61fa42e020f7488786462758f17bbaf2feb0bdceb58f5ee6d0d607bb05448adee814d2ffe892c12eae81fdc3e1467b9eb800ff5acec46abe9eb24c06dff
6
+ metadata.gz: f013c36deef2e22a5c0f50ae0aa173e1db94b965785ac9ebc8f2de2526b1e6b9b4073453ef6f6c1ff9eecc6ff9d199e3df6f855e1e8c5e330426db107f5dcf12
7
+ data.tar.gz: 09a83eabcf713c9a1e2102129a65821a8b448c83165cea308033d8dad14614b7bef79b1661325cdb67672c48f7d641c1868c3b05a18f1ab1d73db5f033bb5187
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,3 +1,3 @@
1
1
  module MacAddr
2
- VERSION = "1.8.1".freeze
2
+ VERSION = "1.8.2".freeze
3
3
  end
data/lib/which.rb ADDED
@@ -0,0 +1,93 @@
1
+ # https://gist.github.com/steakknife/88b6c3837a5e90a08296
2
+ # Copyright (c) 2014 Barry Allard <barry.allard@gmail.com>
3
+ # License: MIT
4
+ #
5
+ # inspiration: https://stackoverflow.com/questions/2889720/one-liner-in-ruby-for-displaying-a-prompt-getting-input-and-assigning-to-a-var
6
+ #
7
+ # Which Bourne shell?
8
+ #
9
+ # require 'which'
10
+ #
11
+ # Which 'sh'
12
+ #
13
+ #
14
+ # Or all zsh(es)
15
+ #
16
+ # require 'which'
17
+ #
18
+ # WhichAll 'zsh'
19
+ #
20
+ module Which
21
+ # similar to `which {{cmd}}`, except relative paths *are* always expanded
22
+ # returns: first match absolute path (String) to cmd (no symlinks followed),
23
+ # or nil if no executable found
24
+ def which(cmd)
25
+ which0(cmd) do |abs_exe|
26
+ return abs_exe
27
+ end
28
+ nil
29
+ end
30
+
31
+ # similar to `which -a {{cmd}}`, except relative paths *are* always expanded
32
+ # returns: always an array, or [] if none found
33
+ def which_all(cmd)
34
+ results = []
35
+ which0(cmd) do |abs_exe|
36
+ results << abs_exe
37
+ end
38
+ results
39
+ end
40
+
41
+ def real_executable?(f)
42
+ File.executable?(f) && !File.directory?(f)
43
+ end
44
+
45
+ def executable_file_extensions
46
+ ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
47
+ end
48
+
49
+ def search_paths
50
+ ENV['PATH'].split(File::PATH_SEPARATOR)
51
+ end
52
+
53
+ def find_executable(path, cmd, &_block)
54
+ executable_file_extensions.each do |ext|
55
+ # rubocop:disable Lint/AssignmentInCondition
56
+ if real_executable?(abs_exe = File.expand_path(cmd + ext, path))
57
+ yield(abs_exe)
58
+ end
59
+ # rubocop:enable Lint/AssignmentInCondition
60
+ end
61
+ end
62
+
63
+ # internal use only
64
+ # +_found_exe+ is yielded to on *all* successful match(es),
65
+ # with path to absolute file (String)
66
+ def which0(cmd, &found_exe)
67
+ # call expand_path(f, nil) == expand_path(f) for relative/abs path cmd
68
+ find_executable(nil, cmd, &found_exe) if File.basename(cmd) != cmd
69
+
70
+ search_paths.each do |path|
71
+ find_executable(path, cmd, &found_exe)
72
+ end
73
+ end
74
+
75
+ module_function(*public_instance_methods) # `extend self`, sorta
76
+ end
77
+
78
+ # make Which() and WhichAll() work
79
+ module Kernel
80
+ # rubocop:disable Style/MethodName
81
+ # return abs-path to +cmd+
82
+ def Which(cmd)
83
+ Which.which cmd
84
+ end
85
+ module_function :Which
86
+
87
+ # return all abs-path(s) to +cmd+ or [] if none
88
+ def WhichAll(cmd)
89
+ Which.which_all cmd
90
+ end
91
+ module_function :WhichAll
92
+ # rubocop:enable Style/MethodName
93
+ end
data/macaddr.gemspec CHANGED
@@ -14,6 +14,7 @@ Gem::Specification::new do |spec|
14
14
  "README",
15
15
  "lib/macaddr.rb",
16
16
  "lib/macaddr/version.rb",
17
+ "lib/which.rb",
17
18
  "macaddr.gemspec",
18
19
  ]
19
20
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: macaddr-steakknife
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.1
4
+ version: 1.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ara T. Howard
@@ -54,6 +54,7 @@ files:
54
54
  - README
55
55
  - lib/macaddr.rb
56
56
  - lib/macaddr/version.rb
57
+ - lib/which.rb
57
58
  - macaddr.gemspec
58
59
  homepage: https://github.com/steakknife/macaddr
59
60
  licenses:
metadata.gz.sig CHANGED
Binary file