Module: PuppetX::Wildfly::DeepHash

Defined in:
lib/puppet_x/wildfly/deep_hash.rb

Instance Method Summary collapse

Instance Method Details

#_deep_intersect(current_state, desired_state) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/puppet_x/wildfly/deep_hash.rb', line 4

def _deep_intersect(current_state, desired_state)
  diff = {}

  current_state.each do |key, value|
    next unless desired_state.is_a? Hash and desired_state.keys.include? key
    diff[key] = if value.is_a? Hash
                  _deep_intersect(value, desired_state[key])
                else
                  value
                end
  end

  diff
end

#_deep_transform_values_in_object(object, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/puppet_x/wildfly/deep_hash.rb', line 19

def _deep_transform_values_in_object(object, &block)
  case object
  when Hash
    object.each_with_object({}) do |(key, value), result|
      result[key] = _deep_transform_values_in_object(value, &block)
    end
  when Array
    object.map { |e| _deep_transform_values_in_object(e, &block) }
  else
    yield(object)
  end
end

#change_to_s(current_value, new_value) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/puppet_x/wildfly/deep_hash.rb', line 41

def change_to_s(current_value, new_value)
  changed_keys = (new_value.to_a - current_value.to_a).collect { |key, _| key }

  current_value = current_value.delete_if { |key, _| !changed_keys.include? key }.inspect
  new_value = new_value.delete_if { |key, _| !changed_keys.include? key }.inspect

  super(current_value, new_value)
end

#insync?(is) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/puppet_x/wildfly/deep_hash.rb', line 36

def insync?(is)
  desired_state = should
  _deep_intersect(is, desired_state) == desired_state
end

#shouldObject



32
33
34
# File 'lib/puppet_x/wildfly/deep_hash.rb', line 32

def should
  _deep_transform_values_in_object(super) { |value| value == :undef ? nil : value }
end