Class: Hash

Inherits:
Object show all
Defined in:
lib/docker/template/patches/hash.rb

Overview

Copyright: 2015 Jordon Bedwell - Apache v2.0 License Encoding: utf-8

Instance Method Summary collapse

Instance Method Details

#any_keys?(*keys) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
# File 'lib/docker/template/patches/hash.rb', line 16

def any_keys?(*keys)
  keys.map(&method(:key?)).any? do |val|
    val == true
  end
end

#deep_merge(newh) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/docker/template/patches/hash.rb', line 48

def deep_merge(newh)
  merge(newh) do |_, oval, nval|
    if oval.is_a?(self.class) && nval.is_a?(self.class)
      then oval.deep_merge(nval) else nval
    end
  end
end

#keys?(*keys) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
# File 'lib/docker/template/patches/hash.rb', line 30

def keys?(*keys)
  return false unless rtn = true && any?
  while rtn && key = keys.shift
    rtn = key?(key) || false
  end
  rtn
end

#leftover_keys?(*keys) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/docker/template/patches/hash.rb', line 24

def leftover_keys?(*keys)
  (self.keys - keys).any?
end

#stringifyObject



58
59
60
61
62
# File 'lib/docker/template/patches/hash.rb', line 58

def stringify
  each_with_object({}) do |(key, val), hsh|
    hsh[key.to_s] = val.is_a?(Array) || val.is_a?(Hash) ? val.stringify : val.to_s
  end
end

#stringify_keysObject



66
67
68
69
70
# File 'lib/docker/template/patches/hash.rb', line 66

def stringify_keys
  each_with_object({}) do |(key, val), hsh|
    hsh[key.to_s] = val
  end
end

#to_envObject



6
7
8
9
10
11
12
# File 'lib/docker/template/patches/hash.rb', line 6

def to_env
  each_with_object({}) do |(key, val), hsh|
    val = val.is_a?(Array) ? val.join(" ") : val.to_s
    key = key.to_s.upcase
    hsh[key] = val
  end
end

#to_env_aryObject



40
41
42
43
44
# File 'lib/docker/template/patches/hash.rb', line 40

def to_env_ary
  each_with_object([]) do |(key, val), ary|
    ary << "#{key}=#{val}"
  end
end