Class: ObjectFormatter
- Inherits:
-
Object
- Object
- ObjectFormatter
- Defined in:
- lib/mismatch_inspectable/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.
- #merge_mismatches(nested_mismatches) ⇒ Object
Constructor Details
#initialize ⇒ ObjectFormatter
Returns a new instance of ObjectFormatter.
4 5 6 |
# File 'lib/mismatch_inspectable/object_formatter.rb', line 4 def initialize @mismatches = {}.extend(DeepMerge) end |
Instance Attribute Details
#mismatches ⇒ Object (readonly)
Returns the value of attribute mismatches.
8 9 10 |
# File 'lib/mismatch_inspectable/object_formatter.rb', line 8 def mismatches @mismatches end |
Instance Method Details
#add_mismatch(prefix, attribute, curr_val, other_val) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/mismatch_inspectable/object_formatter.rb', line 10 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 |
#merge_mismatches(nested_mismatches) ⇒ Object
22 23 24 |
# File 'lib/mismatch_inspectable/object_formatter.rb', line 22 def merge_mismatches(nested_mismatches) mismatches.deep_merge!(nested_mismatches) end |