super_diff 0.11.0 → 0.13.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 (242) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +23 -182
  3. data/lib/super_diff/active_record/differs/active_record_relation.rb +1 -1
  4. data/lib/super_diff/active_record/inspection_tree_builders/active_record_model.rb +57 -0
  5. data/lib/super_diff/active_record/inspection_tree_builders/active_record_relation.rb +34 -0
  6. data/lib/super_diff/active_record/inspection_tree_builders.rb +14 -0
  7. data/lib/super_diff/active_record/monkey_patches.rb +6 -3
  8. data/lib/super_diff/active_record/object_inspection.rb +16 -4
  9. data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +6 -2
  10. data/lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb +1 -1
  11. data/lib/super_diff/active_record/operation_tree_flatteners/active_record_relation.rb +1 -1
  12. data/lib/super_diff/active_record/operation_trees/active_record_relation.rb +1 -1
  13. data/lib/super_diff/active_record.rb +12 -16
  14. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +1 -1
  15. data/lib/super_diff/active_support/inspection_tree_builders/hash_with_indifferent_access.rb +44 -0
  16. data/lib/super_diff/active_support/inspection_tree_builders/ordered_options.rb +44 -0
  17. data/lib/super_diff/active_support/inspection_tree_builders.rb +14 -0
  18. data/lib/super_diff/active_support/object_inspection.rb +16 -4
  19. data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +1 -1
  20. data/lib/super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access.rb +1 -1
  21. data/lib/super_diff/active_support/operation_trees/hash_with_indifferent_access.rb +1 -1
  22. data/lib/super_diff/active_support.rb +11 -15
  23. data/lib/super_diff/basic/diff_formatters/collection.rb +135 -0
  24. data/lib/super_diff/basic/diff_formatters/multiline_string.rb +34 -0
  25. data/lib/super_diff/basic/diff_formatters.rb +11 -0
  26. data/lib/super_diff/basic/differs/array.rb +17 -0
  27. data/lib/super_diff/basic/differs/custom_object.rb +19 -0
  28. data/lib/super_diff/basic/differs/date_like.rb +17 -0
  29. data/lib/super_diff/basic/differs/default_object.rb +24 -0
  30. data/lib/super_diff/basic/differs/hash.rb +17 -0
  31. data/lib/super_diff/basic/differs/multiline_string.rb +18 -0
  32. data/lib/super_diff/basic/differs/time_like.rb +17 -0
  33. data/lib/super_diff/basic/differs.rb +24 -0
  34. data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/array.rb +3 -3
  35. data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/custom_object.rb +3 -3
  36. data/lib/super_diff/basic/inspection_tree_builders/data_object.rb +40 -0
  37. data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/date_like.rb +3 -3
  38. data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/default_object.rb +5 -7
  39. data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/hash.rb +3 -3
  40. data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/primitive.rb +4 -4
  41. data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/time_like.rb +3 -3
  42. data/lib/super_diff/basic/inspection_tree_builders.rb +24 -0
  43. data/lib/super_diff/basic/operation_tree_builders/array.rb +111 -0
  44. data/lib/super_diff/basic/operation_tree_builders/custom_object.rb +42 -0
  45. data/lib/super_diff/basic/operation_tree_builders/data_object.rb +18 -0
  46. data/lib/super_diff/basic/operation_tree_builders/date_like.rb +17 -0
  47. data/lib/super_diff/basic/operation_tree_builders/default_object.rb +117 -0
  48. data/lib/super_diff/basic/operation_tree_builders/hash.rb +222 -0
  49. data/lib/super_diff/basic/operation_tree_builders/multiline_string.rb +90 -0
  50. data/lib/super_diff/basic/operation_tree_builders/time_like.rb +26 -0
  51. data/lib/super_diff/basic/operation_tree_builders.rb +38 -0
  52. data/lib/super_diff/basic/operation_tree_flatteners/array.rb +17 -0
  53. data/lib/super_diff/basic/operation_tree_flatteners/collection.rb +140 -0
  54. data/lib/super_diff/basic/operation_tree_flatteners/custom_object.rb +30 -0
  55. data/lib/super_diff/basic/operation_tree_flatteners/default_object.rb +32 -0
  56. data/lib/super_diff/basic/operation_tree_flatteners/hash.rb +35 -0
  57. data/lib/super_diff/basic/operation_tree_flatteners/multiline_string.rb +20 -0
  58. data/lib/super_diff/basic/operation_tree_flatteners.rb +24 -0
  59. data/lib/super_diff/basic/operation_trees/array.rb +17 -0
  60. data/lib/super_diff/basic/operation_trees/custom_object.rb +17 -0
  61. data/lib/super_diff/basic/operation_trees/default_object.rb +42 -0
  62. data/lib/super_diff/basic/operation_trees/hash.rb +17 -0
  63. data/lib/super_diff/basic/operation_trees/multiline_string.rb +17 -0
  64. data/lib/super_diff/basic/operation_trees.rb +25 -0
  65. data/lib/super_diff/basic.rb +50 -0
  66. data/lib/super_diff/{differs/base.rb → core/abstract_differ.rb} +2 -2
  67. data/lib/super_diff/core/abstract_inspection_tree_builder.rb +26 -0
  68. data/lib/super_diff/{operation_trees/base.rb → core/abstract_operation_tree.rb} +6 -2
  69. data/lib/super_diff/{operation_tree_builders/base.rb → core/abstract_operation_tree_builder.rb} +4 -8
  70. data/lib/super_diff/{operation_tree_flatteners/base.rb → core/abstract_operation_tree_flattener.rb} +2 -2
  71. data/lib/super_diff/{operations → core}/binary_operation.rb +1 -1
  72. data/lib/super_diff/core/colorized_document_extensions.rb +20 -0
  73. data/lib/super_diff/core/configuration.rb +196 -0
  74. data/lib/super_diff/core/differ_dispatcher.rb +31 -0
  75. data/lib/super_diff/core/gem_version.rb +47 -0
  76. data/lib/super_diff/core/helpers.rb +88 -0
  77. data/lib/super_diff/core/implementation_checks.rb +21 -0
  78. data/lib/super_diff/{object_inspection → core}/inspection_tree.rb +7 -6
  79. data/lib/super_diff/core/inspection_tree_builder_dispatcher.rb +23 -0
  80. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_lines_when_rendering_to_lines.rb +9 -3
  81. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_prefix_when_rendering_to_lines.rb +3 -3
  82. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_prelude_when_rendering_to_lines.rb +3 -3
  83. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_single_line.rb +3 -3
  84. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/base.rb +2 -2
  85. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/inspection.rb +7 -11
  86. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/nesting.rb +2 -2
  87. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/only_when.rb +2 -2
  88. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/text.rb +2 -2
  89. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_empty.rb +2 -2
  90. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_non_empty.rb +2 -2
  91. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_rendering_to_lines.rb +2 -2
  92. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_rendering_to_string.rb +2 -2
  93. data/lib/super_diff/core/inspection_tree_nodes.rb +55 -0
  94. data/lib/super_diff/core/line.rb +85 -0
  95. data/lib/super_diff/{errors → core}/no_differ_available_error.rb +1 -1
  96. data/lib/super_diff/core/no_inspection_tree_builder_available_error.rb +21 -0
  97. data/lib/super_diff/core/no_operation_tree_available_error.rb +20 -0
  98. data/lib/super_diff/core/no_operation_tree_builder_available_error.rb +24 -0
  99. data/lib/super_diff/{operation_tree_builders/main.rb → core/operation_tree_builder_dispatcher.rb} +9 -13
  100. data/lib/super_diff/core/operation_tree_finder.rb +27 -0
  101. data/lib/super_diff/core/prefix_for_next_inspection_tree_node.rb +6 -0
  102. data/lib/super_diff/core/prelude_for_next_inspection_tree_node.rb +6 -0
  103. data/lib/super_diff/core/recursion_guard.rb +52 -0
  104. data/lib/super_diff/core/tiered_lines.rb +6 -0
  105. data/lib/super_diff/core/tiered_lines_elider.rb +472 -0
  106. data/lib/super_diff/core/tiered_lines_formatter.rb +77 -0
  107. data/lib/super_diff/{operations → core}/unary_operation.rb +1 -1
  108. data/lib/super_diff/core.rb +69 -0
  109. data/lib/super_diff/csi.rb +0 -32
  110. data/lib/super_diff/differs.rb +19 -12
  111. data/lib/super_diff/equality_matchers/array.rb +3 -3
  112. data/lib/super_diff/equality_matchers/default.rb +8 -3
  113. data/lib/super_diff/equality_matchers/defaults.rb +1 -1
  114. data/lib/super_diff/equality_matchers/hash.rb +3 -3
  115. data/lib/super_diff/equality_matchers/multiline_string.rb +3 -3
  116. data/lib/super_diff/equality_matchers/primitive.rb +3 -3
  117. data/lib/super_diff/equality_matchers/singleline_string.rb +2 -2
  118. data/lib/super_diff/errors.rb +12 -8
  119. data/lib/super_diff/object_inspection.rb +63 -14
  120. data/lib/super_diff/operation_tree_builders.rb +19 -15
  121. data/lib/super_diff/operation_tree_flatteners.rb +19 -16
  122. data/lib/super_diff/operation_trees.rb +19 -9
  123. data/lib/super_diff/operations.rb +12 -2
  124. data/lib/super_diff/rspec/augmented_matcher.rb +1 -1
  125. data/lib/super_diff/rspec/differ.rb +4 -5
  126. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +1 -1
  127. data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
  128. data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
  129. data/lib/super_diff/rspec/differs/object_having_attributes.rb +1 -1
  130. data/lib/super_diff/rspec/inspection_tree_builders/collection_containing_exactly.rb +34 -0
  131. data/lib/super_diff/rspec/inspection_tree_builders/collection_including.rb +40 -0
  132. data/lib/super_diff/rspec/inspection_tree_builders/double.rb +100 -0
  133. data/lib/super_diff/rspec/inspection_tree_builders/generic_describable_matcher.rb +17 -0
  134. data/lib/super_diff/rspec/inspection_tree_builders/hash_including.rb +40 -0
  135. data/lib/super_diff/rspec/inspection_tree_builders/instance_of.rb +25 -0
  136. data/lib/super_diff/rspec/inspection_tree_builders/kind_of.rb +25 -0
  137. data/lib/super_diff/rspec/inspection_tree_builders/object_having_attributes.rb +34 -0
  138. data/lib/super_diff/rspec/inspection_tree_builders/primitive.rb +9 -0
  139. data/lib/super_diff/rspec/inspection_tree_builders/value_within.rb +30 -0
  140. data/lib/super_diff/rspec/inspection_tree_builders.rb +40 -0
  141. data/lib/super_diff/rspec/object_inspection.rb +14 -4
  142. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +4 -4
  143. data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +1 -1
  144. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +1 -1
  145. data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +2 -2
  146. data/lib/super_diff/rspec.rb +20 -18
  147. data/lib/super_diff/version.rb +1 -1
  148. data/lib/super_diff.rb +70 -23
  149. data/spec/examples.txt +450 -543
  150. data/spec/spec_helper.rb +1 -0
  151. data/spec/support/integration/helpers.rb +4 -1
  152. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +1 -1
  153. data/spec/support/models/active_record/person.rb +8 -1
  154. data/spec/support/models/point.rb +7 -0
  155. data/spec/support/shared_examples/active_record.rb +5 -5
  156. data/spec/support/unit/helpers.rb +12 -1
  157. data/spec/support/unit/matchers/be_deprecated_in_favor_of.rb +39 -0
  158. data/spec/unit/active_record/object_inspection_spec.rb +5 -5
  159. data/spec/unit/basic/inspection_tree_builders/data_object_spec.rb +146 -0
  160. data/spec/unit/basic/operation_tree_builders/data_object_spec.rb +82 -0
  161. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/array_spec.rb +8 -8
  162. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/custom_object_spec.rb +9 -9
  163. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/default_object_spec.rb +9 -9
  164. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/hash_spec.rb +8 -8
  165. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/multiline_string_spec.rb +4 -4
  166. data/spec/unit/core/configuration_no_rspec_spec.rb +58 -0
  167. data/spec/unit/core/configuration_spec.rb +176 -0
  168. data/spec/unit/{helpers_spec.rb → core/helpers_spec.rb} +2 -2
  169. data/spec/unit/{tiered_lines_elider_spec.rb → core/tiered_lines_elider_spec.rb} +2 -2
  170. data/spec/unit/{tiered_lines_formatter_spec.rb → core/tiered_lines_formatter_spec.rb} +1 -1
  171. data/spec/unit/deprecations_spec.rb +176 -0
  172. data/spec/unit/equality_matchers/main_spec.rb +5 -5
  173. data/super_diff.gemspec +10 -3
  174. metadata +144 -120
  175. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +0 -51
  176. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +0 -36
  177. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +0 -16
  178. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +0 -46
  179. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb +0 -46
  180. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +0 -16
  181. data/lib/super_diff/colorized_document_extensions.rb +0 -18
  182. data/lib/super_diff/configuration.rb +0 -149
  183. data/lib/super_diff/diff_formatters/collection.rb +0 -132
  184. data/lib/super_diff/diff_formatters/multiline_string.rb +0 -31
  185. data/lib/super_diff/differs/array.rb +0 -15
  186. data/lib/super_diff/differs/custom_object.rb +0 -17
  187. data/lib/super_diff/differs/date_like.rb +0 -15
  188. data/lib/super_diff/differs/default_object.rb +0 -19
  189. data/lib/super_diff/differs/defaults.rb +0 -13
  190. data/lib/super_diff/differs/empty.rb +0 -13
  191. data/lib/super_diff/differs/hash.rb +0 -15
  192. data/lib/super_diff/differs/main.rb +0 -31
  193. data/lib/super_diff/differs/multiline_string.rb +0 -16
  194. data/lib/super_diff/differs/time_like.rb +0 -15
  195. data/lib/super_diff/gem_version.rb +0 -45
  196. data/lib/super_diff/helpers.rb +0 -86
  197. data/lib/super_diff/implementation_checks.rb +0 -19
  198. data/lib/super_diff/line.rb +0 -83
  199. data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +0 -27
  200. data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +0 -15
  201. data/lib/super_diff/object_inspection/inspection_tree_builders/main.rb +0 -30
  202. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +0 -48
  203. data/lib/super_diff/object_inspection/nodes.rb +0 -50
  204. data/lib/super_diff/object_inspection/prefix_for_next_node.rb +0 -6
  205. data/lib/super_diff/object_inspection/prelude_for_next_node.rb +0 -6
  206. data/lib/super_diff/operation_tree_builders/array.rb +0 -107
  207. data/lib/super_diff/operation_tree_builders/custom_object.rb +0 -40
  208. data/lib/super_diff/operation_tree_builders/date_like.rb +0 -15
  209. data/lib/super_diff/operation_tree_builders/default_object.rb +0 -119
  210. data/lib/super_diff/operation_tree_builders/defaults.rb +0 -5
  211. data/lib/super_diff/operation_tree_builders/hash.rb +0 -218
  212. data/lib/super_diff/operation_tree_builders/multiline_string.rb +0 -86
  213. data/lib/super_diff/operation_tree_builders/time_like.rb +0 -24
  214. data/lib/super_diff/operation_tree_flatteners/array.rb +0 -15
  215. data/lib/super_diff/operation_tree_flatteners/collection.rb +0 -136
  216. data/lib/super_diff/operation_tree_flatteners/custom_object.rb +0 -28
  217. data/lib/super_diff/operation_tree_flatteners/default_object.rb +0 -31
  218. data/lib/super_diff/operation_tree_flatteners/hash.rb +0 -33
  219. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +0 -18
  220. data/lib/super_diff/operation_trees/array.rb +0 -15
  221. data/lib/super_diff/operation_trees/custom_object.rb +0 -15
  222. data/lib/super_diff/operation_trees/default_object.rb +0 -40
  223. data/lib/super_diff/operation_trees/defaults.rb +0 -5
  224. data/lib/super_diff/operation_trees/hash.rb +0 -15
  225. data/lib/super_diff/operation_trees/main.rb +0 -35
  226. data/lib/super_diff/operation_trees/multiline_string.rb +0 -15
  227. data/lib/super_diff/recursion_guard.rb +0 -50
  228. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb +0 -36
  229. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +0 -42
  230. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +0 -102
  231. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher.rb +0 -19
  232. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +0 -42
  233. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +0 -27
  234. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +0 -27
  235. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +0 -36
  236. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/primitive.rb +0 -10
  237. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +0 -32
  238. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +0 -48
  239. data/lib/super_diff/tiered_lines.rb +0 -4
  240. data/lib/super_diff/tiered_lines_elider.rb +0 -462
  241. data/lib/super_diff/tiered_lines_formatter.rb +0 -75
  242. data/spec/internal/log/test.log +0 -0
@@ -1,83 +0,0 @@
1
- module SuperDiff
2
- class Line
3
- extend AttrExtras.mixin
4
-
5
- ICONS = { delete: "-", insert: "+", noop: " " }.freeze
6
- COLORS = { insert: :actual, delete: :expected, noop: :plain }.freeze
7
-
8
- rattr_initialize(
9
- [
10
- :type!,
11
- :indentation_level!,
12
- :value!,
13
- prefix: "",
14
- add_comma: false,
15
- children: [],
16
- elided: false,
17
- collection_bookend: nil,
18
- complete_bookend: nil
19
- ]
20
- )
21
- attr_query :add_comma?
22
- attr_query :elided?
23
-
24
- def clone_with(overrides = {})
25
- self.class.new(
26
- type: type,
27
- indentation_level: indentation_level,
28
- prefix: prefix,
29
- value: value,
30
- add_comma: add_comma?,
31
- children: children,
32
- elided: elided?,
33
- collection_bookend: collection_bookend,
34
- complete_bookend: complete_bookend,
35
- **overrides
36
- )
37
- end
38
-
39
- def icon
40
- ICONS.fetch(type)
41
- end
42
-
43
- def color
44
- COLORS.fetch(type)
45
- end
46
-
47
- def with_comma
48
- clone_with(add_comma: true)
49
- end
50
-
51
- def as_elided
52
- clone_with(elided: true)
53
- end
54
-
55
- def with_value_prepended(prelude)
56
- clone_with(value: prelude + value)
57
- end
58
-
59
- def with_value_appended(suffix)
60
- clone_with(value: value + suffix)
61
- end
62
-
63
- def prefixed_with(prefix)
64
- clone_with(prefix: prefix + self.prefix)
65
- end
66
-
67
- def with_complete_bookend(complete_bookend)
68
- clone_with(complete_bookend: complete_bookend)
69
- end
70
-
71
- def opens_collection?
72
- collection_bookend == :open
73
- end
74
-
75
- def closes_collection?
76
- collection_bookend == :close
77
- end
78
-
79
- def complete_bookend?
80
- complete_bookend != nil
81
- end
82
- end
83
- end
@@ -1,27 +0,0 @@
1
- module SuperDiff
2
- module ObjectInspection
3
- module InspectionTreeBuilders
4
- class Base
5
- extend AttrExtras.mixin
6
- extend ImplementationChecks
7
- include ImplementationChecks
8
-
9
- def self.applies_to?(_value)
10
- unimplemented_class_method!
11
- end
12
-
13
- method_object :object
14
-
15
- def call
16
- unimplemented_instance_method!
17
- end
18
-
19
- protected
20
-
21
- def inspection_tree
22
- unimplemented_instance_method!
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,15 +0,0 @@
1
- module SuperDiff
2
- module ObjectInspection
3
- module InspectionTreeBuilders
4
- DEFAULTS = [
5
- CustomObject,
6
- Array,
7
- Hash,
8
- Primitive,
9
- TimeLike,
10
- DateLike,
11
- DefaultObject
12
- ].freeze
13
- end
14
- end
15
- end
@@ -1,30 +0,0 @@
1
- module SuperDiff
2
- module ObjectInspection
3
- module InspectionTreeBuilders
4
- class Main
5
- extend AttrExtras.mixin
6
-
7
- method_object :object
8
-
9
- def call
10
- if resolved_class
11
- resolved_class.call(object)
12
- else
13
- raise NoInspectorAvailableError.create(object)
14
- end
15
- end
16
-
17
- private
18
-
19
- def resolved_class
20
- available_classes.find { |klass| klass.applies_to?(object) }
21
- end
22
-
23
- def available_classes
24
- SuperDiff.configuration.extra_inspection_tree_builder_classes +
25
- DEFAULTS
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,48 +0,0 @@
1
- module SuperDiff
2
- module ObjectInspection
3
- module InspectionTreeBuilders
4
- autoload(
5
- :Base,
6
- "super_diff/object_inspection/inspection_tree_builders/base"
7
- )
8
- autoload(
9
- :Array,
10
- "super_diff/object_inspection/inspection_tree_builders/array"
11
- )
12
- autoload(
13
- :CustomObject,
14
- "super_diff/object_inspection/inspection_tree_builders/custom_object"
15
- )
16
- autoload(
17
- :DefaultObject,
18
- "super_diff/object_inspection/inspection_tree_builders/default_object"
19
- )
20
- autoload(
21
- :Hash,
22
- "super_diff/object_inspection/inspection_tree_builders/hash"
23
- )
24
- autoload(
25
- :Main,
26
- "super_diff/object_inspection/inspection_tree_builders/main"
27
- )
28
- autoload(
29
- :Primitive,
30
- "super_diff/object_inspection/inspection_tree_builders/primitive"
31
- )
32
- autoload(
33
- :String,
34
- "super_diff/object_inspection/inspection_tree_builders/string"
35
- )
36
- autoload(
37
- :TimeLike,
38
- "super_diff/object_inspection/inspection_tree_builders/time_like"
39
- )
40
- autoload(
41
- :DateLike,
42
- "super_diff/object_inspection/inspection_tree_builders/date_like"
43
- )
44
- end
45
- end
46
- end
47
-
48
- require "super_diff/object_inspection/inspection_tree_builders/defaults"
@@ -1,50 +0,0 @@
1
- module SuperDiff
2
- module ObjectInspection
3
- module Nodes
4
- autoload(
5
- :AsLinesWhenRenderingToLines,
6
- "super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines"
7
- )
8
- autoload(
9
- :AsPrefixWhenRenderingToLines,
10
- "super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines"
11
- )
12
- autoload(
13
- :AsPreludeWhenRenderingToLines,
14
- "super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines"
15
- )
16
- autoload(
17
- :AsSingleLine,
18
- "super_diff/object_inspection/nodes/as_single_line"
19
- )
20
- autoload :Base, "super_diff/object_inspection/nodes/base"
21
- autoload :Inspection, "super_diff/object_inspection/nodes/inspection"
22
- autoload :Nesting, "super_diff/object_inspection/nodes/nesting"
23
- autoload :OnlyWhen, "super_diff/object_inspection/nodes/only_when"
24
- autoload :Text, "super_diff/object_inspection/nodes/text"
25
- autoload(
26
- :WhenRenderingToLines,
27
- "super_diff/object_inspection/nodes/when_rendering_to_lines"
28
- )
29
- autoload(
30
- :WhenRenderingToString,
31
- "super_diff/object_inspection/nodes/when_rendering_to_string"
32
- )
33
-
34
- def self.registry
35
- @_registry ||= [
36
- AsLinesWhenRenderingToLines,
37
- AsPrefixWhenRenderingToLines,
38
- AsPreludeWhenRenderingToLines,
39
- AsSingleLine,
40
- Inspection,
41
- Nesting,
42
- OnlyWhen,
43
- Text,
44
- WhenRenderingToLines,
45
- WhenRenderingToString
46
- ]
47
- end
48
- end
49
- end
50
- end
@@ -1,6 +0,0 @@
1
- module SuperDiff
2
- module ObjectInspection
3
- class PrefixForNextNode < String
4
- end
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- module SuperDiff
2
- module ObjectInspection
3
- class PreludeForNextNode < String
4
- end
5
- end
6
- end
@@ -1,107 +0,0 @@
1
- module SuperDiff
2
- module OperationTreeBuilders
3
- class Array < Base
4
- def self.applies_to?(expected, actual)
5
- expected.is_a?(::Array) && actual.is_a?(::Array)
6
- end
7
-
8
- def call
9
- Diff::LCS.traverse_balanced(expected, actual, lcs_callbacks)
10
- operation_tree
11
- end
12
-
13
- private
14
-
15
- def lcs_callbacks
16
- @_lcs_callbacks ||=
17
- LcsCallbacks.new(
18
- operation_tree: operation_tree,
19
- expected: expected,
20
- actual: actual,
21
- compare: method(:compare)
22
- )
23
- end
24
-
25
- def operation_tree
26
- @_operation_tree ||= OperationTrees::Array.new([])
27
- end
28
-
29
- class LcsCallbacks
30
- extend AttrExtras.mixin
31
-
32
- pattr_initialize %i[operation_tree! expected! actual! compare!]
33
- public :operation_tree
34
-
35
- def match(event)
36
- add_noop_operation(event)
37
- end
38
-
39
- def discard_a(event)
40
- add_delete_operation(event)
41
- end
42
-
43
- def discard_b(event)
44
- add_insert_operation(event)
45
- end
46
-
47
- def change(event)
48
- children = compare.(event.old_element, event.new_element)
49
-
50
- if children
51
- add_change_operation(event, children)
52
- else
53
- add_delete_operation(event)
54
- add_insert_operation(event)
55
- end
56
- end
57
-
58
- private
59
-
60
- def add_delete_operation(event)
61
- operation_tree << Operations::UnaryOperation.new(
62
- name: :delete,
63
- collection: expected,
64
- key: event.old_position,
65
- value: event.old_element,
66
- index: event.old_position
67
- )
68
- end
69
-
70
- def add_insert_operation(event)
71
- operation_tree << Operations::UnaryOperation.new(
72
- name: :insert,
73
- collection: actual,
74
- key: event.new_position,
75
- value: event.new_element,
76
- index: event.new_position
77
- )
78
- end
79
-
80
- def add_noop_operation(event)
81
- operation_tree << Operations::UnaryOperation.new(
82
- name: :noop,
83
- collection: actual,
84
- key: event.new_position,
85
- value: event.new_element,
86
- index: event.new_position
87
- )
88
- end
89
-
90
- def add_change_operation(event, children)
91
- operation_tree << Operations::BinaryOperation.new(
92
- name: :change,
93
- left_collection: expected,
94
- right_collection: actual,
95
- left_key: event.old_position,
96
- right_key: event.new_position,
97
- left_value: event.old_element,
98
- right_value: event.new_element,
99
- left_index: event.old_position,
100
- right_index: event.new_position,
101
- children: children
102
- )
103
- end
104
- end
105
- end
106
- end
107
- end
@@ -1,40 +0,0 @@
1
- module SuperDiff
2
- module OperationTreeBuilders
3
- class CustomObject < DefaultObject
4
- def self.applies_to?(expected, actual)
5
- expected.class == actual.class &&
6
- expected.respond_to?(:attributes_for_super_diff) &&
7
- actual.respond_to?(:attributes_for_super_diff)
8
- end
9
-
10
- protected
11
-
12
- def build_operation_tree
13
- # NOTE: It doesn't matter whether we use expected or actual here,
14
- # because all we care about is the name of the class
15
- OperationTrees::CustomObject.new([], underlying_object: actual)
16
- end
17
-
18
- def attribute_names
19
- expected.attributes_for_super_diff.keys &
20
- actual.attributes_for_super_diff.keys
21
- end
22
-
23
- private
24
-
25
- attr_reader :expected_attributes, :actual_attributes
26
-
27
- def establish_expected_and_actual_attributes
28
- @expected_attributes =
29
- attribute_names.reduce({}) do |hash, name|
30
- hash.merge(name => expected.public_send(name))
31
- end
32
-
33
- @actual_attributes =
34
- attribute_names.reduce({}) do |hash, name|
35
- hash.merge(name => actual.public_send(name))
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,15 +0,0 @@
1
- module SuperDiff
2
- module OperationTreeBuilders
3
- class DateLike < CustomObject
4
- def self.applies_to?(expected, actual)
5
- SuperDiff.date_like?(expected) && SuperDiff.date_like?(actual)
6
- end
7
-
8
- protected
9
-
10
- def attribute_names
11
- %w[year month day]
12
- end
13
- end
14
- end
15
- end
@@ -1,119 +0,0 @@
1
- module SuperDiff
2
- module OperationTreeBuilders
3
- class DefaultObject < Base
4
- def self.applies_to?(_expected, _actual)
5
- true
6
- end
7
-
8
- def initialize(*args)
9
- super(*args)
10
-
11
- establish_expected_and_actual_attributes
12
- end
13
-
14
- protected
15
-
16
- def unary_operations
17
- attribute_names.reduce([]) do |operations, name|
18
- possibly_add_noop_operation_to(operations, name)
19
- possibly_add_delete_operation_to(operations, name)
20
- possibly_add_insert_operation_to(operations, name)
21
- operations
22
- end
23
- end
24
-
25
- def build_operation_tree
26
- # XXX This assumes that `expected` and `actual` are the same
27
- # TODO: Does this need to be find_operation_tree_for?
28
- OperationTrees::DefaultObject.new([], underlying_object: actual)
29
- end
30
-
31
- def find_operation_tree_for(value)
32
- OperationTrees::Main.call(value)
33
- end
34
-
35
- def attribute_names
36
- (
37
- expected.instance_variables.sort & actual.instance_variables.sort
38
- ).map { |variable_name| variable_name[1..-1] }
39
- end
40
-
41
- private
42
-
43
- attr_reader :expected_attributes, :actual_attributes
44
-
45
- def establish_expected_and_actual_attributes
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
55
- end
56
-
57
- def possibly_add_noop_operation_to(operations, attribute_name)
58
- if should_add_noop_operation?(attribute_name)
59
- operations << Operations::UnaryOperation.new(
60
- name: :noop,
61
- collection: actual_attributes,
62
- key: attribute_name,
63
- index: attribute_names.index(attribute_name),
64
- value: actual_attributes[attribute_name]
65
- )
66
- end
67
- end
68
-
69
- def should_add_noop_operation?(attribute_name)
70
- expected_attributes.include?(attribute_name) &&
71
- actual_attributes.include?(attribute_name) &&
72
- expected_attributes[attribute_name] ==
73
- actual_attributes[attribute_name]
74
- end
75
-
76
- def possibly_add_delete_operation_to(operations, attribute_name)
77
- if should_add_delete_operation?(attribute_name)
78
- operations << Operations::UnaryOperation.new(
79
- name: :delete,
80
- collection: expected_attributes,
81
- key: attribute_name,
82
- index: attribute_names.index(attribute_name),
83
- value: expected_attributes[attribute_name]
84
- )
85
- end
86
- end
87
-
88
- def should_add_delete_operation?(attribute_name)
89
- expected_attributes.include?(attribute_name) &&
90
- (
91
- !actual_attributes.include?(attribute_name) ||
92
- expected_attributes[attribute_name] !=
93
- actual_attributes[attribute_name]
94
- )
95
- end
96
-
97
- def possibly_add_insert_operation_to(operations, attribute_name)
98
- if should_add_insert_operation?(attribute_name)
99
- operations << Operations::UnaryOperation.new(
100
- name: :insert,
101
- collection: actual_attributes,
102
- key: attribute_name,
103
- index: attribute_names.index(attribute_name),
104
- value: actual_attributes[attribute_name]
105
- )
106
- end
107
- end
108
-
109
- def should_add_insert_operation?(attribute_name)
110
- !expected_attributes.include?(attribute_name) ||
111
- (
112
- actual_attributes.include?(attribute_name) &&
113
- expected_attributes[attribute_name] !=
114
- actual_attributes[attribute_name]
115
- )
116
- end
117
- end
118
- end
119
- end
@@ -1,5 +0,0 @@
1
- module SuperDiff
2
- module OperationTreeBuilders
3
- DEFAULTS = [Array, Hash, TimeLike, DateLike, CustomObject].freeze
4
- end
5
- end