Class: SuperDiff::ActiveSupport::OperationTreeBuilders::HashWithIndifferentAccess

Inherits:
OperationTreeBuilders::Hash show all
Defined in:
lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OperationTreeBuilders::Base

#call

Constructor Details

#initialize(expected:, actual:, **rest) ⇒ HashWithIndifferentAccess

Returns a new instance of HashWithIndifferentAccess.



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb', line 15

def initialize(expected:, actual:, **rest)
  super

  if expected.is_a?(::HashWithIndifferentAccess)
    @expected = expected.to_h
    @actual = actual.transform_keys(&:to_s)
  end

  if actual.is_a?(::HashWithIndifferentAccess)
    @expected = expected.transform_keys(&:to_s)
    @actual = actual.to_h
  end
end

Class Method Details

.applies_to?(expected, actual) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
10
11
12
13
# File 'lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb', line 5

def self.applies_to?(expected, actual)
  (
    expected.is_a?(::HashWithIndifferentAccess) && actual.is_a?(::Hash)
  ) ||
    (
      expected.is_a?(::Hash) &&
        actual.is_a?(::HashWithIndifferentAccess)
    )
end