Class: ObjectFormatter
- Inherits:
-
MismatchInspectable::Formatter
- Object
- MismatchInspectable::Formatter
- ObjectFormatter
- Defined in:
- lib/mismatch_inspectable/formatter/object_formatter.rb
Instance Attribute Summary collapse
-
#mismatches ⇒ Object
readonly
Returns the value of attribute mismatches.
Instance Method Summary collapse
- #add_mismatch(prefix, attribute, curr_val, other_val) ⇒ Object
-
#initialize ⇒ ObjectFormatter
constructor
A new instance of ObjectFormatter.
- #process_mismatches(nested_mismatches) ⇒ Object
Methods inherited from MismatchInspectable::Formatter
Constructor Details
#initialize ⇒ ObjectFormatter
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
#mismatches ⇒ Object (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 |