Class: Hash
Overview
Copyright: 2015 Jordon Bedwell - Apache v2.0 License Encoding: utf-8
Instance Method Summary collapse
- #any_keys?(*keys) ⇒ Boolean
- #deep_merge(newh) ⇒ Object
- #keys?(*keys) ⇒ Boolean
- #leftover_keys?(*keys) ⇒ Boolean
- #stringify ⇒ Object
- #stringify_keys ⇒ Object
- #to_env ⇒ Object
- #to_env_ary ⇒ Object
Instance Method Details
#any_keys?(*keys) ⇒ 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
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
24 25 26 |
# File 'lib/docker/template/patches/hash.rb', line 24 def leftover_keys?(*keys) (self.keys - keys).any? end |
#stringify ⇒ Object
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_keys ⇒ Object
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_env ⇒ Object
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_ary ⇒ Object
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 |