Module: RSpecSystem::Util

Included in:
NodeSet::VagrantBase, Prefab
Defined in:
lib/rspec-system/util.rb

Overview

A set of utilities that can be used as a mixin.

Instance Method Summary collapse

Instance Method Details

#deep_merge!(dest_hash, other_hash) ⇒ Hash

This is based on the Hash#deep_merge! method from activesupport

Parameters:

  • dest_hash (Hash)

    hash to save merged values into

  • other_hash (Hash)

    hash to merge values from

Returns:

  • (Hash)

    dest_hash



32
33
34
35
36
37
38
# File 'lib/rspec-system/util.rb', line 32

def deep_merge!(dest_hash, other_hash)
  other_hash.each_pair do |k,v|
    tv = dest_hash[k]
    dest_hash[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? deep_merge!(tv.dup, v) : v
  end
  dest_hash
end

#shellescape(str) ⇒ String

This is the shellescape method from shellwords from ruby-2.0.0

Parameters:

  • str (String)

    string to escape

Returns:

  • (String)

    returns escaped string



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rspec-system/util.rb', line 7

def shellescape(str)
  str = str.to_s

  # An empty argument will be skipped, so return empty quotes.
  return "''" if str.empty?

  str = str.dup

  # Treat multibyte characters as is.  It is caller's responsibility
  # to encode the string in the right encoding for the shell
  # environment.
  str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/, "\\\\\\1")

  # A LF cannot be escaped with a backslash because a backslash + LF
  # combo is regarded as line continuation and simply ignored.
  str.gsub!(/\n/, "'\n'")

  return str
end