super_diff 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +65 -26
  3. data/lib/super_diff/active_record/differs/active_record_relation.rb +1 -2
  4. data/lib/super_diff/active_record/differs.rb +1 -1
  5. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +5 -13
  6. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +1 -3
  7. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +2 -2
  8. data/lib/super_diff/active_record/object_inspection.rb +1 -1
  9. data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +1 -2
  10. data/lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb +1 -2
  11. data/lib/super_diff/active_record/operation_tree_builders.rb +2 -2
  12. data/lib/super_diff/active_record/operation_tree_flatteners.rb +1 -1
  13. data/lib/super_diff/active_record/operation_trees.rb +1 -1
  14. data/lib/super_diff/active_record.rb +7 -15
  15. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +5 -6
  16. data/lib/super_diff/active_support/differs.rb +1 -1
  17. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +3 -9
  18. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +1 -1
  19. data/lib/super_diff/active_support/object_inspection.rb +1 -1
  20. data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +5 -6
  21. data/lib/super_diff/active_support/operation_tree_builders.rb +1 -1
  22. data/lib/super_diff/active_support/operation_tree_flatteners.rb +1 -1
  23. data/lib/super_diff/active_support/operation_trees.rb +1 -1
  24. data/lib/super_diff/active_support.rb +6 -11
  25. data/lib/super_diff/colorized_document_extensions.rb +2 -4
  26. data/lib/super_diff/configuration.rb +14 -8
  27. data/lib/super_diff/csi/color.rb +4 -4
  28. data/lib/super_diff/csi/colorized_document.rb +12 -16
  29. data/lib/super_diff/csi/document.rb +8 -19
  30. data/lib/super_diff/csi/eight_bit_color.rb +19 -19
  31. data/lib/super_diff/csi/four_bit_color.rb +82 -31
  32. data/lib/super_diff/csi/twenty_four_bit_color.rb +12 -11
  33. data/lib/super_diff/csi/uncolorized_document.rb +2 -6
  34. data/lib/super_diff/csi.rb +10 -14
  35. data/lib/super_diff/diff_formatters/collection.rb +35 -41
  36. data/lib/super_diff/differs/default_object.rb +1 -1
  37. data/lib/super_diff/differs/defaults.rb +1 -1
  38. data/lib/super_diff/differs/main.rb +2 -13
  39. data/lib/super_diff/equality_matchers/array.rb +10 -12
  40. data/lib/super_diff/equality_matchers/base.rb +1 -1
  41. data/lib/super_diff/equality_matchers/default.rb +2 -4
  42. data/lib/super_diff/equality_matchers/defaults.rb +1 -1
  43. data/lib/super_diff/equality_matchers/hash.rb +10 -12
  44. data/lib/super_diff/equality_matchers/multiline_string.rb +11 -13
  45. data/lib/super_diff/equality_matchers/primitive.rb +10 -12
  46. data/lib/super_diff/equality_matchers/singleline_string.rb +10 -12
  47. data/lib/super_diff/equality_matchers.rb +1 -1
  48. data/lib/super_diff/errors.rb +3 -3
  49. data/lib/super_diff/gem_version.rb +3 -3
  50. data/lib/super_diff/helpers.rb +10 -10
  51. data/lib/super_diff/implementation_checks.rb +2 -2
  52. data/lib/super_diff/line.rb +3 -3
  53. data/lib/super_diff/object_inspection/inspection_tree.rb +46 -60
  54. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +2 -6
  55. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +3 -9
  56. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +5 -14
  57. data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +1 -1
  58. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +4 -12
  59. data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +6 -23
  60. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +9 -9
  61. data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +8 -20
  62. data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +1 -5
  63. data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +1 -5
  64. data/lib/super_diff/object_inspection/nodes/as_single_line.rb +3 -7
  65. data/lib/super_diff/object_inspection/nodes/base.rb +9 -14
  66. data/lib/super_diff/object_inspection/nodes/inspection.rb +26 -34
  67. data/lib/super_diff/object_inspection/nodes/nesting.rb +1 -1
  68. data/lib/super_diff/object_inspection/nodes/only_when.rb +2 -6
  69. data/lib/super_diff/object_inspection/nodes/text.rb +1 -5
  70. data/lib/super_diff/object_inspection/nodes/when_empty.rb +2 -6
  71. data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +2 -6
  72. data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +1 -1
  73. data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +1 -5
  74. data/lib/super_diff/object_inspection/nodes.rb +7 -7
  75. data/lib/super_diff/object_inspection.rb +3 -3
  76. data/lib/super_diff/operation_tree_builders/array.rb +12 -11
  77. data/lib/super_diff/operation_tree_builders/base.rb +17 -15
  78. data/lib/super_diff/operation_tree_builders/custom_object.rb +8 -6
  79. data/lib/super_diff/operation_tree_builders/default_object.rb +29 -21
  80. data/lib/super_diff/operation_tree_builders/hash.rb +23 -24
  81. data/lib/super_diff/operation_tree_builders/main.rb +4 -11
  82. data/lib/super_diff/operation_tree_builders/multiline_string.rb +3 -3
  83. data/lib/super_diff/operation_tree_builders/time_like.rb +1 -11
  84. data/lib/super_diff/operation_tree_builders.rb +1 -1
  85. data/lib/super_diff/operation_tree_flatteners/base.rb +1 -5
  86. data/lib/super_diff/operation_tree_flatteners/collection.rb +13 -16
  87. data/lib/super_diff/operation_tree_flatteners/default_object.rb +1 -2
  88. data/lib/super_diff/operation_tree_flatteners/hash.rb +2 -10
  89. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +2 -1
  90. data/lib/super_diff/operation_tree_flatteners.rb +3 -3
  91. data/lib/super_diff/operation_trees/base.rb +3 -5
  92. data/lib/super_diff/operation_trees/default_object.rb +1 -3
  93. data/lib/super_diff/operations/binary_operation.rb +2 -2
  94. data/lib/super_diff/operations/unary_operation.rb +1 -1
  95. data/lib/super_diff/rails.rb +2 -1
  96. data/lib/super_diff/recursion_guard.rb +5 -4
  97. data/lib/super_diff/rspec/augmented_matcher.rb +4 -5
  98. data/lib/super_diff/rspec/differ.rb +6 -13
  99. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -2
  100. data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
  101. data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
  102. data/lib/super_diff/rspec/differs.rb +3 -3
  103. data/lib/super_diff/rspec/matcher_text_builders/base.rb +13 -15
  104. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +5 -7
  105. data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +3 -5
  106. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +1 -5
  107. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +2 -6
  108. data/lib/super_diff/rspec/matcher_text_builders.rb +5 -8
  109. data/lib/super_diff/rspec/matcher_text_template.rb +13 -16
  110. data/lib/super_diff/rspec/monkey_patches.rb +122 -116
  111. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +8 -6
  112. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +11 -16
  113. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +2 -1
  114. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +8 -6
  115. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +8 -6
  116. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +9 -9
  117. data/lib/super_diff/rspec/object_inspection.rb +1 -1
  118. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +11 -10
  119. data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +7 -6
  120. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +11 -10
  121. data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +22 -17
  122. data/lib/super_diff/rspec/operation_tree_builders.rb +4 -4
  123. data/lib/super_diff/rspec.rb +11 -13
  124. data/lib/super_diff/tiered_lines_elider.rb +87 -115
  125. data/lib/super_diff/tiered_lines_formatter.rb +5 -9
  126. data/lib/super_diff/version.rb +1 -1
  127. data/lib/super_diff.rb +4 -9
  128. data/spec/examples.txt +493 -485
  129. data/spec/integration/rails/active_record_spec.rb +3 -1
  130. data/spec/integration/rails/engines_spec.rb +20 -0
  131. data/spec/integration/rails/hash_with_indifferent_access_spec.rb +3 -1
  132. data/spec/integration/rspec/be_falsey_matcher_spec.rb +40 -35
  133. data/spec/integration/rspec/be_matcher_spec.rb +360 -320
  134. data/spec/integration/rspec/be_nil_matcher_spec.rb +38 -34
  135. data/spec/integration/rspec/be_predicate_matcher_spec.rb +376 -359
  136. data/spec/integration/rspec/be_truthy_matcher_spec.rb +38 -33
  137. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +242 -239
  138. data/spec/integration/rspec/eq_matcher_spec.rb +595 -557
  139. data/spec/integration/rspec/have_attributes_matcher_spec.rb +294 -286
  140. data/spec/integration/rspec/have_predicate_matcher_spec.rb +291 -297
  141. data/spec/integration/rspec/include_matcher_spec.rb +317 -215
  142. data/spec/integration/rspec/match_array_matcher_spec.rb +276 -273
  143. data/spec/integration/rspec/match_matcher_spec.rb +847 -834
  144. data/spec/integration/rspec/raise_error_matcher_spec.rb +468 -453
  145. data/spec/integration/rspec/respond_to_matcher_spec.rb +702 -697
  146. data/spec/integration/rspec/third_party_matcher_spec.rb +142 -138
  147. data/spec/integration/rspec/unhandled_errors_spec.rb +88 -84
  148. data/spec/spec_helper.rb +17 -20
  149. data/spec/support/command_runner.rb +34 -57
  150. data/spec/support/integration/helpers.rb +35 -28
  151. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +28 -23
  152. data/spec/support/integration/test_programs/base.rb +12 -17
  153. data/spec/support/integration/test_programs/plain.rb +6 -0
  154. data/spec/support/integration/test_programs/rspec_active_record.rb +4 -1
  155. data/spec/support/integration/test_programs/rspec_active_support.rb +4 -1
  156. data/spec/support/integration/test_programs/rspec_rails.rb +4 -1
  157. data/spec/support/integration/test_programs/rspec_rails_engine.rb +30 -0
  158. data/spec/support/models/active_record/person.rb +6 -4
  159. data/spec/support/models/active_record/shipping_address.rb +9 -10
  160. data/spec/support/models/customer.rb +2 -4
  161. data/spec/support/models/player.rb +3 -6
  162. data/spec/support/models/shipping_address.rb +4 -13
  163. data/spec/support/shared_examples/active_record.rb +232 -214
  164. data/spec/support/shared_examples/active_support.rb +53 -51
  165. data/spec/support/shared_examples/elided_diffs.rb +405 -381
  166. data/spec/support/shared_examples/hash_with_indifferent_access.rb +424 -388
  167. data/spec/support/shared_examples/key.rb +123 -0
  168. data/spec/support/unit/helpers.rb +1 -3
  169. data/spec/support/unit/matchers/match_output.rb +12 -13
  170. data/spec/unit/active_record/object_inspection_spec.rb +222 -206
  171. data/spec/unit/equality_matchers/main_spec.rb +1049 -984
  172. data/spec/unit/helpers_spec.rb +14 -21
  173. data/spec/unit/operation_tree_flatteners/array_spec.rb +557 -524
  174. data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +619 -601
  175. data/spec/unit/operation_tree_flatteners/default_object_spec.rb +619 -621
  176. data/spec/unit/operation_tree_flatteners/hash_spec.rb +595 -556
  177. data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +102 -92
  178. data/spec/unit/rspec/matchers/be_compared_to_spec.rb +3 -3
  179. data/spec/unit/rspec/matchers/be_predicate_spec.rb +3 -3
  180. data/spec/unit/rspec/matchers/contain_exactly_spec.rb +1 -1
  181. data/spec/unit/rspec/matchers/have_attributes_spec.rb +1 -1
  182. data/spec/unit/rspec/matchers/have_predicate_spec.rb +2 -2
  183. data/spec/unit/rspec/matchers/include_spec.rb +2 -2
  184. data/spec/unit/rspec/matchers/match_array_spec.rb +2 -2
  185. data/spec/unit/rspec/matchers/raise_error_spec.rb +5 -5
  186. data/spec/unit/rspec/matchers/respond_to_spec.rb +23 -16
  187. data/spec/unit/rspec/object_inspection_spec.rb +349 -324
  188. data/spec/unit/super_diff_spec.rb +1542 -1449
  189. data/spec/unit/tiered_lines_elider_spec.rb +3508 -3536
  190. data/spec/unit/tiered_lines_formatter_spec.rb +54 -116
  191. data/super_diff.gemspec +13 -12
  192. metadata +73 -73
  193. data/spec/tmp/warnings_logger/all_warnings.txt +0 -2
@@ -18,7 +18,7 @@ module SuperDiff
18
18
  render_to_lines_in_subtree(
19
19
  object,
20
20
  type: type,
21
- indentation_level: indentation_level + 1,
21
+ indentation_level: indentation_level + 1
22
22
  )
23
23
  end
24
24
  end
@@ -18,11 +18,7 @@ module SuperDiff
18
18
  end
19
19
 
20
20
  def render_to_string(object)
21
- if test_passes?
22
- render_to_string_in_subtree(object)
23
- else
24
- ""
25
- end
21
+ test_passes? ? render_to_string_in_subtree(object) : ""
26
22
  end
27
23
 
28
24
  def render_to_lines(object, type:, indentation_level:)
@@ -30,7 +26,7 @@ module SuperDiff
30
26
  render_to_lines_in_subtree(
31
27
  object,
32
28
  type: type,
33
- indentation_level: indentation_level,
29
+ indentation_level: indentation_level
34
30
  )
35
31
  else
36
32
  []
@@ -11,11 +11,7 @@ module SuperDiff
11
11
  end
12
12
 
13
13
  def render_to_string(object)
14
- if block
15
- evaluate_block(object).to_s
16
- else
17
- immediate_value.to_s
18
- end
14
+ block ? evaluate_block(object).to_s : immediate_value.to_s
19
15
  end
20
16
 
21
17
  def render_to_lines(object, **)
@@ -11,11 +11,7 @@ module SuperDiff
11
11
  end
12
12
 
13
13
  def render_to_string(object)
14
- if empty?(object)
15
- render_to_string_in_subtree(object)
16
- else
17
- ""
18
- end
14
+ empty?(object) ? render_to_string_in_subtree(object) : ""
19
15
  end
20
16
 
21
17
  def render_to_lines(object, type:, indentation_level:)
@@ -23,7 +19,7 @@ module SuperDiff
23
19
  render_to_lines_in_subtree(
24
20
  object,
25
21
  type: type,
26
- indentation_level: indentation_level,
22
+ indentation_level: indentation_level
27
23
  )
28
24
  else
29
25
  []
@@ -11,11 +11,7 @@ module SuperDiff
11
11
  end
12
12
 
13
13
  def render_to_string(object)
14
- if empty?(object)
15
- ""
16
- else
17
- render_to_string_in_subtree(object)
18
- end
14
+ empty?(object) ? "" : render_to_string_in_subtree(object)
19
15
  end
20
16
 
21
17
  def render_to_lines(object, type:, indentation_level:)
@@ -25,7 +21,7 @@ module SuperDiff
25
21
  render_to_lines_in_subtree(
26
22
  object,
27
23
  type: type,
28
- indentation_level: indentation_level,
24
+ indentation_level: indentation_level
29
25
  )
30
26
  end
31
27
  end
@@ -18,7 +18,7 @@ module SuperDiff
18
18
  render_to_lines_in_subtree(
19
19
  object,
20
20
  type: type,
21
- indentation_level: indentation_level,
21
+ indentation_level: indentation_level
22
22
  )
23
23
  end
24
24
  end
@@ -11,11 +11,7 @@ module SuperDiff
11
11
  end
12
12
 
13
13
  def render_to_string(object)
14
- if block
15
- render_to_string_in_subtree(object)
16
- else
17
- immediate_value.to_s
18
- end
14
+ block ? render_to_string_in_subtree(object) : immediate_value.to_s
19
15
  end
20
16
 
21
17
  def render_to_lines(*, **)
@@ -3,19 +3,19 @@ module SuperDiff
3
3
  module Nodes
4
4
  autoload(
5
5
  :AsLinesWhenRenderingToLines,
6
- "super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines",
6
+ "super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines"
7
7
  )
8
8
  autoload(
9
9
  :AsPrefixWhenRenderingToLines,
10
- "super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines",
10
+ "super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines"
11
11
  )
12
12
  autoload(
13
13
  :AsPreludeWhenRenderingToLines,
14
- "super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines",
14
+ "super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines"
15
15
  )
16
16
  autoload(
17
17
  :AsSingleLine,
18
- "super_diff/object_inspection/nodes/as_single_line",
18
+ "super_diff/object_inspection/nodes/as_single_line"
19
19
  )
20
20
  autoload :Base, "super_diff/object_inspection/nodes/base"
21
21
  autoload :Inspection, "super_diff/object_inspection/nodes/inspection"
@@ -24,11 +24,11 @@ module SuperDiff
24
24
  autoload :Text, "super_diff/object_inspection/nodes/text"
25
25
  autoload(
26
26
  :WhenRenderingToLines,
27
- "super_diff/object_inspection/nodes/when_rendering_to_lines",
27
+ "super_diff/object_inspection/nodes/when_rendering_to_lines"
28
28
  )
29
29
  autoload(
30
30
  :WhenRenderingToString,
31
- "super_diff/object_inspection/nodes/when_rendering_to_string",
31
+ "super_diff/object_inspection/nodes/when_rendering_to_string"
32
32
  )
33
33
 
34
34
  def self.registry
@@ -42,7 +42,7 @@ module SuperDiff
42
42
  OnlyWhen,
43
43
  Text,
44
44
  WhenRenderingToLines,
45
- WhenRenderingToString,
45
+ WhenRenderingToString
46
46
  ]
47
47
  end
48
48
  end
@@ -3,16 +3,16 @@ module SuperDiff
3
3
  autoload :InspectionTree, "super_diff/object_inspection/inspection_tree"
4
4
  autoload(
5
5
  :InspectionTreeBuilders,
6
- "super_diff/object_inspection/inspection_tree_builders",
6
+ "super_diff/object_inspection/inspection_tree_builders"
7
7
  )
8
8
  autoload :Nodes, "super_diff/object_inspection/nodes"
9
9
  autoload(
10
10
  :PrefixForNextNode,
11
- "super_diff/object_inspection/prefix_for_next_node",
11
+ "super_diff/object_inspection/prefix_for_next_node"
12
12
  )
13
13
  autoload(
14
14
  :PreludeForNextNode,
15
- "super_diff/object_inspection/prelude_for_next_node",
15
+ "super_diff/object_inspection/prelude_for_next_node"
16
16
  )
17
17
  end
18
18
  end
@@ -13,12 +13,13 @@ module SuperDiff
13
13
  private
14
14
 
15
15
  def lcs_callbacks
16
- @_lcs_callbacks ||= LcsCallbacks.new(
17
- operation_tree: operation_tree,
18
- expected: expected,
19
- actual: actual,
20
- compare: method(:compare),
21
- )
16
+ @_lcs_callbacks ||=
17
+ LcsCallbacks.new(
18
+ operation_tree: operation_tree,
19
+ expected: expected,
20
+ actual: actual,
21
+ compare: method(:compare)
22
+ )
22
23
  end
23
24
 
24
25
  def operation_tree
@@ -28,7 +29,7 @@ module SuperDiff
28
29
  class LcsCallbacks
29
30
  extend AttrExtras.mixin
30
31
 
31
- pattr_initialize [:operation_tree!, :expected!, :actual!, :compare!]
32
+ pattr_initialize %i[operation_tree! expected! actual! compare!]
32
33
  public :operation_tree
33
34
 
34
35
  def match(event)
@@ -62,7 +63,7 @@ module SuperDiff
62
63
  collection: expected,
63
64
  key: event.old_position,
64
65
  value: event.old_element,
65
- index: event.old_position,
66
+ index: event.old_position
66
67
  )
67
68
  end
68
69
 
@@ -72,7 +73,7 @@ module SuperDiff
72
73
  collection: actual,
73
74
  key: event.new_position,
74
75
  value: event.new_element,
75
- index: event.new_position,
76
+ index: event.new_position
76
77
  )
77
78
  end
78
79
 
@@ -82,7 +83,7 @@ module SuperDiff
82
83
  collection: actual,
83
84
  key: event.new_position,
84
85
  value: event.new_element,
85
- index: event.new_position,
86
+ index: event.new_position
86
87
  )
87
88
  end
88
89
 
@@ -97,7 +98,7 @@ module SuperDiff
97
98
  right_value: event.new_element,
98
99
  left_index: event.old_position,
99
100
  right_index: event.new_position,
100
- children: children,
101
+ children: children
101
102
  )
102
103
  end
103
104
  end
@@ -8,7 +8,7 @@ module SuperDiff
8
8
  extend AttrExtras.mixin
9
9
  include ImplementationChecks
10
10
 
11
- method_object [:expected!, :actual!]
11
+ method_object %i[expected! actual!]
12
12
 
13
13
  def call
14
14
  operation_tree
@@ -33,16 +33,20 @@ module SuperDiff
33
33
 
34
34
  unary_operations.each_with_index do |operation, index|
35
35
  if (
36
- operation.name == :insert &&
37
- (delete_operation = unmatched_delete_operations.find { |op| op.key == operation.key }) &&
38
- (insert_operation = operation)
39
- )
36
+ operation.name == :insert &&
37
+ (
38
+ delete_operation =
39
+ unmatched_delete_operations.find do |op|
40
+ op.key == operation.key
41
+ end
42
+ ) && (insert_operation = operation)
43
+ )
40
44
  unmatched_delete_operations.delete(delete_operation)
41
45
 
42
- if (children = possible_comparison_of(
43
- delete_operation,
44
- insert_operation,
45
- ))
46
+ if (
47
+ children =
48
+ possible_comparison_of(delete_operation, insert_operation)
49
+ )
46
50
  operation_tree.delete(delete_operation)
47
51
  operation_tree << Operations::BinaryOperation.new(
48
52
  name: :change,
@@ -54,7 +58,7 @@ module SuperDiff
54
58
  right_value: insert_operation.collection[operation.key],
55
59
  left_index: delete_operation.index,
56
60
  right_index: insert_operation.index,
57
- children: children,
61
+ children: children
58
62
  )
59
63
  else
60
64
  operation_tree << insert_operation
@@ -80,17 +84,15 @@ module SuperDiff
80
84
  end
81
85
 
82
86
  def should_compare?(operation, next_operation)
83
- next_operation &&
84
- operation.name == :delete &&
85
- next_operation.name == :insert &&
86
- next_operation.key == operation.key
87
+ next_operation && operation.name == :delete &&
88
+ next_operation.name == :insert && next_operation.key == operation.key
87
89
  end
88
90
 
89
91
  def compare(expected, actual)
90
92
  OperationTreeBuilders::Main.call(
91
93
  expected: expected,
92
94
  actual: actual,
93
- all_or_nothing: false,
95
+ all_or_nothing: false
94
96
  )
95
97
  end
96
98
  end
@@ -25,13 +25,15 @@ module SuperDiff
25
25
  attr_reader :expected_attributes, :actual_attributes
26
26
 
27
27
  def establish_expected_and_actual_attributes
28
- @expected_attributes = attribute_names.reduce({}) do |hash, name|
29
- hash.merge(name => expected.public_send(name))
30
- end
28
+ @expected_attributes =
29
+ attribute_names.reduce({}) do |hash, name|
30
+ hash.merge(name => expected.public_send(name))
31
+ end
31
32
 
32
- @actual_attributes = attribute_names.reduce({}) do |hash, name|
33
- hash.merge(name => actual.public_send(name))
34
- end
33
+ @actual_attributes =
34
+ attribute_names.reduce({}) do |hash, name|
35
+ hash.merge(name => actual.public_send(name))
36
+ end
35
37
  end
36
38
  end
37
39
  end
@@ -33,8 +33,9 @@ module SuperDiff
33
33
  end
34
34
 
35
35
  def attribute_names
36
- (expected.instance_variables.sort & actual.instance_variables.sort).
37
- map { |variable_name| variable_name[1..-1] }
36
+ (
37
+ expected.instance_variables.sort & actual.instance_variables.sort
38
+ ).map { |variable_name| variable_name[1..-1] }
38
39
  end
39
40
 
40
41
  private
@@ -42,13 +43,15 @@ module SuperDiff
42
43
  attr_reader :expected_attributes, :actual_attributes
43
44
 
44
45
  def establish_expected_and_actual_attributes
45
- @expected_attributes = attribute_names.reduce({}) do |hash, name|
46
- hash.merge(name => expected.instance_variable_get("@#{name}"))
47
- end
48
-
49
- @actual_attributes = attribute_names.reduce({}) do |hash, name|
50
- hash.merge(name => actual.instance_variable_get("@#{name}"))
51
- end
46
+ @expected_attributes =
47
+ attribute_names.reduce({}) do |hash, name|
48
+ hash.merge(name => expected.instance_variable_get("@#{name}"))
49
+ end
50
+
51
+ @actual_attributes =
52
+ attribute_names.reduce({}) do |hash, name|
53
+ hash.merge(name => actual.instance_variable_get("@#{name}"))
54
+ end
52
55
  end
53
56
 
54
57
  def possibly_add_noop_operation_to(operations, attribute_name)
@@ -58,7 +61,7 @@ module SuperDiff
58
61
  collection: actual_attributes,
59
62
  key: attribute_name,
60
63
  index: attribute_names.index(attribute_name),
61
- value: actual_attributes[attribute_name],
64
+ value: actual_attributes[attribute_name]
62
65
  )
63
66
  end
64
67
  end
@@ -66,7 +69,8 @@ module SuperDiff
66
69
  def should_add_noop_operation?(attribute_name)
67
70
  expected_attributes.include?(attribute_name) &&
68
71
  actual_attributes.include?(attribute_name) &&
69
- expected_attributes[attribute_name] == actual_attributes[attribute_name]
72
+ expected_attributes[attribute_name] ==
73
+ actual_attributes[attribute_name]
70
74
  end
71
75
 
72
76
  def possibly_add_delete_operation_to(operations, attribute_name)
@@ -76,16 +80,18 @@ module SuperDiff
76
80
  collection: expected_attributes,
77
81
  key: attribute_name,
78
82
  index: attribute_names.index(attribute_name),
79
- value: expected_attributes[attribute_name],
83
+ value: expected_attributes[attribute_name]
80
84
  )
81
85
  end
82
86
  end
83
87
 
84
88
  def should_add_delete_operation?(attribute_name)
85
- expected_attributes.include?(attribute_name) && (
86
- !actual_attributes.include?(attribute_name) ||
87
- expected_attributes[attribute_name] != actual_attributes[attribute_name]
88
- )
89
+ expected_attributes.include?(attribute_name) &&
90
+ (
91
+ !actual_attributes.include?(attribute_name) ||
92
+ expected_attributes[attribute_name] !=
93
+ actual_attributes[attribute_name]
94
+ )
89
95
  end
90
96
 
91
97
  def possibly_add_insert_operation_to(operations, attribute_name)
@@ -95,16 +101,18 @@ module SuperDiff
95
101
  collection: actual_attributes,
96
102
  key: attribute_name,
97
103
  index: attribute_names.index(attribute_name),
98
- value: actual_attributes[attribute_name],
104
+ value: actual_attributes[attribute_name]
99
105
  )
100
106
  end
101
107
  end
102
108
 
103
109
  def should_add_insert_operation?(attribute_name)
104
- !expected_attributes.include?(attribute_name) || (
105
- actual_attributes.include?(attribute_name) &&
106
- expected_attributes[attribute_name] != actual_attributes[attribute_name]
107
- )
110
+ !expected_attributes.include?(attribute_name) ||
111
+ (
112
+ actual_attributes.include?(attribute_name) &&
113
+ expected_attributes[attribute_name] !=
114
+ actual_attributes[attribute_name]
115
+ )
108
116
  end
109
117
  end
110
118
  end
@@ -53,18 +53,18 @@ module SuperDiff
53
53
  ev2, av2 = expected[ek], actual[ek]
54
54
 
55
55
  if (
56
- (!actual.include?(ek) || ev2 != av2) &&
57
- operations.none? { |operation|
58
- [:delete, :noop].include?(operation.name) &&
59
- operation.key == ek
60
- }
61
- )
56
+ (!actual.include?(ek) || ev2 != av2) &&
57
+ operations.none? do |operation|
58
+ %i[delete noop].include?(operation.name) &&
59
+ operation.key == ek
60
+ end
61
+ )
62
62
  operations << Operations::UnaryOperation.new(
63
63
  name: :delete,
64
64
  collection: expected,
65
65
  key: ek,
66
66
  value: ev2,
67
- index: ei2,
67
+ index: ei2
68
68
  )
69
69
  end
70
70
  end
@@ -75,16 +75,16 @@ module SuperDiff
75
75
  collection: actual,
76
76
  key: ak,
77
77
  value: av,
78
- index: ai,
78
+ index: ai
79
79
  )
80
80
  else
81
81
  # (If we're here, it probably means that the key in 'actual' isn't
82
82
  # present in 'expected' or the values don't match.)
83
83
 
84
84
  if (
85
- (operations.empty? || operations.last.name == :noop) &&
86
- (ai == 0 || eks.include?(aks[ai - 1]))
87
- )
85
+ (operations.empty? || operations.last.name == :noop) &&
86
+ (ai == 0 || eks.include?(aks[ai - 1]))
87
+ )
88
88
  # If we go from a match in the last iteration to a missing or
89
89
  # extra key in this one, or we're at the first key in 'actual' and
90
90
  # it's missing or extra, look for deletes in the 'expected' hash
@@ -113,10 +113,10 @@ module SuperDiff
113
113
  # handled in some future iteration of the 'actual' loop.
114
114
  break
115
115
  elsif (
116
- aks[ai + 1 .. -1].any? { |k|
117
- expected.include?(k) && expected[k] != actual[k]
118
- }
119
- )
116
+ aks[ai + 1..-1].any? do |k|
117
+ expected.include?(k) && expected[k] != actual[k]
118
+ end
119
+ )
120
120
  # While we backtracked a bit to iterate over 'expected', we
121
121
  # now have to look ahead. If we will end up encountering a
122
122
  # insert that matches this delete later, stop and go back to
@@ -130,7 +130,7 @@ module SuperDiff
130
130
  collection: expected,
131
131
  key: ek,
132
132
  value: ev,
133
- index: ei2,
133
+ index: ei2
134
134
  )
135
135
  end
136
136
 
@@ -144,17 +144,16 @@ module SuperDiff
144
144
  collection: actual,
145
145
  key: ak,
146
146
  value: av,
147
- index: ai,
147
+ index: ai
148
148
  )
149
149
  end
150
150
  end
151
151
  end
152
152
 
153
153
  if (
154
- expected.include?(ak) &&
155
- ev != av &&
156
- operations.none? { |op| op.name == :delete && op.key == ak }
157
- )
154
+ expected.include?(ak) && ev != av &&
155
+ operations.none? { |op| op.name == :delete && op.key == ak }
156
+ )
158
157
  # If we're here, it means that we didn't encounter any delete
159
158
  # operations above for whatever reason and so we need to add a
160
159
  # delete to represent the fact that the value for this key has
@@ -164,7 +163,7 @@ module SuperDiff
164
163
  collection: expected,
165
164
  key: ak,
166
165
  value: expected[ak],
167
- index: ei,
166
+ index: ei
168
167
  )
169
168
  end
170
169
 
@@ -178,7 +177,7 @@ module SuperDiff
178
177
  collection: actual,
179
178
  key: ak,
180
179
  value: av,
181
- index: ai,
180
+ index: ai
182
181
  )
183
182
  end
184
183
  end
@@ -200,7 +199,7 @@ module SuperDiff
200
199
  collection: expected,
201
200
  key: ek,
202
201
  value: ev,
203
- index: ei,
202
+ index: ei
204
203
  )
205
204
  end
206
205
 
@@ -3,14 +3,11 @@ module SuperDiff
3
3
  class Main
4
4
  extend AttrExtras.mixin
5
5
 
6
- method_object [:expected!, :actual!, :all_or_nothing!]
6
+ method_object %i[expected! actual! all_or_nothing!]
7
7
 
8
8
  def call
9
9
  if resolved_class
10
- resolved_class.call(
11
- expected: expected,
12
- actual: actual,
13
- )
10
+ resolved_class.call(expected: expected, actual: actual)
14
11
  elsif all_or_nothing?
15
12
  raise NoOperationTreeBuilderAvailableError.create(expected, actual)
16
13
  else
@@ -29,13 +26,9 @@ module SuperDiff
29
26
  def available_classes
30
27
  classes =
31
28
  SuperDiff.configuration.extra_operation_tree_builder_classes +
32
- DEFAULTS
29
+ DEFAULTS
33
30
 
34
- if all_or_nothing?
35
- classes + [DefaultObject]
36
- else
37
- classes
38
- end
31
+ all_or_nothing? ? classes + [DefaultObject] : classes
39
32
  end
40
33
  end
41
34
  end
@@ -53,7 +53,7 @@ module SuperDiff
53
53
  collection: expected,
54
54
  key: index,
55
55
  index: index,
56
- value: expected[index],
56
+ value: expected[index]
57
57
  )
58
58
  end
59
59
  end
@@ -65,7 +65,7 @@ module SuperDiff
65
65
  collection: actual,
66
66
  key: index,
67
67
  index: index,
68
- value: actual[index],
68
+ value: actual[index]
69
69
  )
70
70
  end
71
71
  end
@@ -77,7 +77,7 @@ module SuperDiff
77
77
  collection: actual,
78
78
  key: index,
79
79
  index: index,
80
- value: actual[index],
80
+ value: actual[index]
81
81
  )
82
82
  end
83
83
  end
@@ -8,17 +8,7 @@ module SuperDiff
8
8
  protected
9
9
 
10
10
  def attribute_names
11
- base = [
12
- "year",
13
- "month",
14
- "day",
15
- "hour",
16
- "min",
17
- "sec",
18
- "subsec",
19
- "zone",
20
- "utc_offset",
21
- ]
11
+ base = %w[year month day hour min sec subsec zone utc_offset]
22
12
 
23
13
  # If timezones are different, also show a normalized timestamp at the
24
14
  # end of the diff to help visualize why they are different moments in
@@ -9,7 +9,7 @@ module SuperDiff
9
9
  # TODO: Where is this used?
10
10
  autoload(
11
11
  :MultilineString,
12
- "super_diff/operation_tree_builders/multiline_string",
12
+ "super_diff/operation_tree_builders/multiline_string"
13
13
  )
14
14
  autoload :TimeLike, "super_diff/operation_tree_builders/time_like"
15
15
  end
@@ -29,11 +29,7 @@ module SuperDiff
29
29
  end
30
30
 
31
31
  def middle_lines
32
- if tiered_lines.empty?
33
- []
34
- else
35
- tiered_lines[1..-2]
36
- end
32
+ tiered_lines.empty? ? [] : tiered_lines[1..-2]
37
33
  end
38
34
 
39
35
  def ending_lines