Class: ObjectFormatter

Inherits:
MismatchInspectable::Formatter show all
Defined in:
lib/mismatch_inspectable/formatter/object_formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from MismatchInspectable::Formatter

#merge_mismatches

Constructor Details

#initializeObjectFormatter

Returns a new instance of ObjectFormatter.



5
6
7
8
# File 'lib/mismatch_inspectable/formatter/object_formatter.rb', line 5

def initialize
  super
  @mismatches = {}.extend(DeepMerge)
end

Instance Attribute Details

#mismatchesObject (readonly)

Returns the value of attribute mismatches.



10
11
12
# File 'lib/mismatch_inspectable/formatter/object_formatter.rb', line 10

def mismatches
  @mismatches
end

Instance Method Details

#add_mismatch(prefix, attribute, curr_val, other_val) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mismatch_inspectable/formatter/object_formatter.rb', line 12

def add_mismatch(prefix, attribute, curr_val, other_val)
  prefix_parts = prefix.split(".").flat_map { |part| part.split("#") }.collect(&:to_sym)
  curr = mismatches

  prefix_parts.each do |part|
    curr[part] ||= {}
    curr = curr[part]
  end

  curr[attribute] = [curr_val, other_val]
end

#process_mismatches(nested_mismatches) ⇒ Object



24
25
26
# File 'lib/mismatch_inspectable/formatter/object_formatter.rb', line 24

def process_mismatches(nested_mismatches)
  mismatches.deep_merge!(nested_mismatches)
end