atk_toolbox 0.0.103 → 0.0.104

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
  SHA256:
3
- metadata.gz: e2460aed2031cdaff8ce3ad1462bb7ff132f1c2f9bba1a08aad2e01f62d436c4
4
- data.tar.gz: 2ea9f6a60938c47469b09193b6ec8961181ce81bdbf24ba23f1fe15aa1c8b20f
3
+ metadata.gz: a0a6d59658071c79365f3123c13fea6f273b40e5bbed9c5f72043d6361a0a630
4
+ data.tar.gz: 64064bdc88621871c55c26cfc9471de3234703c9d7111303b3464e9f79065c6c
5
5
  SHA512:
6
- metadata.gz: 7ad280dcdd1a99b0acda1a26d0c45e6e865b17ee4ee74b9eaf4ce38236181a41f89847a29f4f3c51b1d1cf859e3b0986c216c4af68228847f4a119366185343c
7
- data.tar.gz: a7706b272bae670227ae640631c5088762f3f3f78140205af7791fed8671cd036ccecde31164f1fffe8f3d63f73274976459127fa699bdd74937d6d7417d2181
6
+ metadata.gz: 769fdbdc25e60ca4cb623ee49e54b8c9f54da4947fb4ca74c635661488c3b7a72a161f85737e9893eec46cb1012417aba1d3230747532a0532ac96489a75449d
7
+ data.tar.gz: e2acfbfeec69c4cfa3a38308b18908454486995f401526bb1605fdcf988226e685b3840411d8770f878f45d7bbe385bdf1bb3db1b7bc556f487a029679549de3
data/lib/atk/os.rb CHANGED
@@ -43,6 +43,20 @@ os_heirarchy = {
43
43
  "android" => {},
44
44
  }
45
45
 
46
+ # this statment was extracted from the ptools gem, credit should go to them
47
+ # https://github.com/djberg96/ptools/blob/master/lib/ptools.rb
48
+ # The WIN32EXTS string is used as part of a Dir[] call in certain methods.
49
+ if File::ALT_SEPARATOR
50
+ MSWINDOWS = true
51
+ if ENV['PATHEXT']
52
+ WIN32EXTS = ('.{' + ENV['PATHEXT'].tr(';', ',').tr('.','') + '}').downcase
53
+ else
54
+ WIN32EXTS = '.{exe,com,bat}'
55
+ end
56
+ else
57
+ MSWINDOWS = false
58
+ end
59
+
46
60
  # TODO: look into using https://github.com/piotrmurach/tty-platform
47
61
 
48
62
  #
@@ -105,21 +119,52 @@ module OS
105
119
  end
106
120
 
107
121
  def self.path_for_executable(name_of_executable)
108
- if OS.is?(:windows)
109
- begin
110
- # TODO: need to escape this value for both double quote and single quotes
111
- output = `powershell -command "(Get-Command '#{name_of_executable}')"`.strip
112
- # if the command doesn't exist it throws an error
113
- rescue
114
- output = ""
122
+ # this method was extracted from the ptools gem, credit should go to them
123
+ # https://github.com/djberg96/ptools/blob/master/lib/ptools.rb
124
+ # this complex method is in favor of just calling the command line because command line calls are slow
125
+ path=ENV['PATH']
126
+ if path.nil? || path.empty?
127
+ raise ArgumentError, "path cannot be empty"
128
+ end
129
+
130
+ # Bail out early if an absolute path is provided.
131
+ if program =~ /^\/|^[a-z]:[\\\/]/i
132
+ program += WIN32EXTS if MSWINDOWS && File.extname(program).empty?
133
+ found = Dir[program].first
134
+ if found && File.executable?(found) && !File.directory?(found)
135
+ return found
136
+ else
137
+ return nil
115
138
  end
116
- return output
117
- else
118
- return `which '#{name_of_executable}'`.strip
119
139
  end
140
+
141
+ # Iterate over each path glob the dir + program.
142
+ path.split(File::PATH_SEPARATOR).each{ |dir|
143
+ dir = File.expand_path(dir)
144
+
145
+ next unless File.exist?(dir) # In case of bogus second argument
146
+ file = File.join(dir, program)
147
+
148
+ # Dir[] doesn't handle backslashes properly, so convert them. Also, if
149
+ # the program name doesn't have an extension, try them all.
150
+ if MSWINDOWS
151
+ file = file.tr("\\", "/")
152
+ file += WIN32EXTS if File.extname(program).empty?
153
+ end
154
+
155
+ found = Dir[file].first
156
+
157
+ # Convert all forward slashes to backslashes if supported
158
+ if found && File.executable?(found) && !File.directory?(found)
159
+ found.tr!(File::SEPARATOR, File::ALT_SEPARATOR) if File::ALT_SEPARATOR
160
+ return found
161
+ end
162
+ }
163
+
164
+ return nil
120
165
  end
121
166
 
122
167
  def self.has_command(name_of_executable)
123
- return OS.path_for_executable(name_of_executable) != ''
168
+ return OS.path_for_executable(name_of_executable) != nil
124
169
  end
125
170
  end
@@ -1,3 +1,3 @@
1
1
  module AtkToolbox
2
- VERSION = '0.0.103'
2
+ VERSION = '0.0.104'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atk_toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.103
4
+ version: 0.0.104
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Hykin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-30 00:00:00.000000000 Z
11
+ date: 2019-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zip
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  version: '0'
136
136
  requirements: []
137
137
  rubyforge_project:
138
- rubygems_version: 2.7.3
138
+ rubygems_version: 2.7.6.2
139
139
  signing_key:
140
140
  specification_version: 4
141
141
  summary: The Ruby gem for all the standard tools ATK uses internally