Module: Ferrum::Browser::Binary

Defined in:
lib/ferrum/browser/binary.rb

Class Method Summary collapse

Class Method Details

.all(commands) ⇒ Object



12
13
14
# File 'lib/ferrum/browser/binary.rb', line 12

def all(commands)
  enum(commands).force
end

.enum(commands) ⇒ Object



16
17
18
19
20
# File 'lib/ferrum/browser/binary.rb', line 16

def enum(commands)
  paths, exts = prepare_paths
  cmds = Array(commands).product(paths, exts)
  lazy_find(cmds)
end

.find(commands) ⇒ Object



8
9
10
# File 'lib/ferrum/browser/binary.rb', line 8

def find(commands)
  enum(commands).first
end

.lazy_find(cmds) ⇒ Object

rubocop:disable Style/CollectionCompact



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ferrum/browser/binary.rb', line 31

def lazy_find(cmds)
  cmds.lazy.map do |cmd, path, ext|
    absolute_path = File.absolute_path(cmd)
    is_absolute_path = absolute_path == cmd
    cmd = File.expand_path("#{cmd}#{ext}", path) unless is_absolute_path

    next unless File.executable?(cmd)
    next if File.directory?(cmd)

    cmd
  end.reject(&:nil?) # .compact isn't defined on Enumerator::Lazy
end

.prepare_pathsObject

Raises:



22
23
24
25
26
27
28
# File 'lib/ferrum/browser/binary.rb', line 22

def prepare_paths
  exts = (ENV.key?("PATHEXT") ? ENV.fetch("PATHEXT").split(";") : []) << ""
  paths = ENV["PATH"].split(File::PATH_SEPARATOR)
  raise EmptyPathError if paths.empty?

  [paths, exts]
end