Module: Anyway::Utils

Defined in:
lib/anyway/utils/which.rb,
lib/anyway/utils/deep_merge.rb

Class Method Summary collapse

Class Method Details

.deep_merge!(source, other) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/anyway/utils/deep_merge.rb', line 7

def self.deep_merge!(source, other)
  other.each do |key, other_value|
    this_value = source[key]

    if this_value.is_a?(::Hash) && other_value.is_a?(::Hash)
      deep_merge!(this_value, other_value)
    else
      source[key] = other_value.deep_dup
    end
  end

  source
end

.which(cmd) ⇒ Object

Cross-platform solution taken from stackoverflow.com/a/5471032



7
8
9
10
11
12
13
14
15
16
# File 'lib/anyway/utils/which.rb', line 7

def self.which(cmd)
  exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
  ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
    exts.each do |ext|
      exe = File.join(path, "#{cmd}#{ext}")
      return exe if File.executable?(exe) && !File.directory?(exe)
    end
  end
  nil
end