super_diff 0.11.0 → 0.12.1

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 (231) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -166
  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/{object_inspection → basic}/inspection_tree_builders/date_like.rb +3 -3
  37. data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/default_object.rb +5 -7
  38. data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/hash.rb +3 -3
  39. data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/primitive.rb +3 -3
  40. data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/time_like.rb +3 -3
  41. data/lib/super_diff/basic/inspection_tree_builders.rb +20 -0
  42. data/lib/super_diff/basic/operation_tree_builders/array.rb +111 -0
  43. data/lib/super_diff/basic/operation_tree_builders/custom_object.rb +42 -0
  44. data/lib/super_diff/basic/operation_tree_builders/date_like.rb +17 -0
  45. data/lib/super_diff/basic/operation_tree_builders/default_object.rb +117 -0
  46. data/lib/super_diff/basic/operation_tree_builders/hash.rb +222 -0
  47. data/lib/super_diff/basic/operation_tree_builders/multiline_string.rb +90 -0
  48. data/lib/super_diff/basic/operation_tree_builders/time_like.rb +26 -0
  49. data/lib/super_diff/basic/operation_tree_builders.rb +34 -0
  50. data/lib/super_diff/basic/operation_tree_flatteners/array.rb +17 -0
  51. data/lib/super_diff/basic/operation_tree_flatteners/collection.rb +140 -0
  52. data/lib/super_diff/basic/operation_tree_flatteners/custom_object.rb +30 -0
  53. data/lib/super_diff/basic/operation_tree_flatteners/default_object.rb +32 -0
  54. data/lib/super_diff/basic/operation_tree_flatteners/hash.rb +35 -0
  55. data/lib/super_diff/basic/operation_tree_flatteners/multiline_string.rb +20 -0
  56. data/lib/super_diff/basic/operation_tree_flatteners.rb +24 -0
  57. data/lib/super_diff/basic/operation_trees/array.rb +17 -0
  58. data/lib/super_diff/basic/operation_trees/custom_object.rb +17 -0
  59. data/lib/super_diff/basic/operation_trees/default_object.rb +42 -0
  60. data/lib/super_diff/basic/operation_trees/hash.rb +17 -0
  61. data/lib/super_diff/basic/operation_trees/multiline_string.rb +17 -0
  62. data/lib/super_diff/basic/operation_trees.rb +25 -0
  63. data/lib/super_diff/basic.rb +48 -0
  64. data/lib/super_diff/{differs/base.rb → core/abstract_differ.rb} +2 -2
  65. data/lib/super_diff/core/abstract_inspection_tree_builder.rb +26 -0
  66. data/lib/super_diff/{operation_trees/base.rb → core/abstract_operation_tree.rb} +6 -2
  67. data/lib/super_diff/{operation_tree_builders/base.rb → core/abstract_operation_tree_builder.rb} +4 -8
  68. data/lib/super_diff/{operation_tree_flatteners/base.rb → core/abstract_operation_tree_flattener.rb} +2 -2
  69. data/lib/super_diff/{operations → core}/binary_operation.rb +1 -1
  70. data/lib/super_diff/core/colorized_document_extensions.rb +20 -0
  71. data/lib/super_diff/core/configuration.rb +192 -0
  72. data/lib/super_diff/core/differ_dispatcher.rb +31 -0
  73. data/lib/super_diff/core/gem_version.rb +47 -0
  74. data/lib/super_diff/core/helpers.rb +88 -0
  75. data/lib/super_diff/core/implementation_checks.rb +21 -0
  76. data/lib/super_diff/{object_inspection → core}/inspection_tree.rb +7 -6
  77. data/lib/super_diff/core/inspection_tree_builder_dispatcher.rb +23 -0
  78. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_lines_when_rendering_to_lines.rb +9 -3
  79. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_prefix_when_rendering_to_lines.rb +3 -3
  80. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_prelude_when_rendering_to_lines.rb +3 -3
  81. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_single_line.rb +3 -3
  82. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/base.rb +2 -2
  83. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/inspection.rb +7 -11
  84. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/nesting.rb +2 -2
  85. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/only_when.rb +2 -2
  86. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/text.rb +2 -2
  87. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_empty.rb +2 -2
  88. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_non_empty.rb +2 -2
  89. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_rendering_to_lines.rb +2 -2
  90. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_rendering_to_string.rb +2 -2
  91. data/lib/super_diff/core/inspection_tree_nodes.rb +55 -0
  92. data/lib/super_diff/core/line.rb +85 -0
  93. data/lib/super_diff/{errors → core}/no_differ_available_error.rb +1 -1
  94. data/lib/super_diff/core/no_inspection_tree_builder_available_error.rb +21 -0
  95. data/lib/super_diff/core/no_operation_tree_available_error.rb +20 -0
  96. data/lib/super_diff/core/no_operation_tree_builder_available_error.rb +24 -0
  97. data/lib/super_diff/{operation_tree_builders/main.rb → core/operation_tree_builder_dispatcher.rb} +9 -13
  98. data/lib/super_diff/core/operation_tree_finder.rb +27 -0
  99. data/lib/super_diff/core/prefix_for_next_inspection_tree_node.rb +6 -0
  100. data/lib/super_diff/core/prelude_for_next_inspection_tree_node.rb +6 -0
  101. data/lib/super_diff/core/recursion_guard.rb +52 -0
  102. data/lib/super_diff/core/tiered_lines.rb +6 -0
  103. data/lib/super_diff/core/tiered_lines_elider.rb +472 -0
  104. data/lib/super_diff/core/tiered_lines_formatter.rb +77 -0
  105. data/lib/super_diff/{operations → core}/unary_operation.rb +1 -1
  106. data/lib/super_diff/core.rb +69 -0
  107. data/lib/super_diff/differs.rb +19 -12
  108. data/lib/super_diff/equality_matchers/array.rb +3 -3
  109. data/lib/super_diff/equality_matchers/default.rb +8 -3
  110. data/lib/super_diff/equality_matchers/hash.rb +3 -3
  111. data/lib/super_diff/equality_matchers/multiline_string.rb +3 -3
  112. data/lib/super_diff/equality_matchers/primitive.rb +3 -3
  113. data/lib/super_diff/equality_matchers/singleline_string.rb +2 -2
  114. data/lib/super_diff/errors.rb +12 -8
  115. data/lib/super_diff/object_inspection.rb +63 -14
  116. data/lib/super_diff/operation_tree_builders.rb +19 -15
  117. data/lib/super_diff/operation_tree_flatteners.rb +19 -16
  118. data/lib/super_diff/operation_trees.rb +19 -9
  119. data/lib/super_diff/operations.rb +12 -2
  120. data/lib/super_diff/rspec/augmented_matcher.rb +1 -1
  121. data/lib/super_diff/rspec/differ.rb +4 -5
  122. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +1 -1
  123. data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
  124. data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
  125. data/lib/super_diff/rspec/differs/object_having_attributes.rb +1 -1
  126. data/lib/super_diff/rspec/inspection_tree_builders/collection_containing_exactly.rb +34 -0
  127. data/lib/super_diff/rspec/inspection_tree_builders/collection_including.rb +40 -0
  128. data/lib/super_diff/rspec/inspection_tree_builders/double.rb +100 -0
  129. data/lib/super_diff/rspec/inspection_tree_builders/generic_describable_matcher.rb +17 -0
  130. data/lib/super_diff/rspec/inspection_tree_builders/hash_including.rb +40 -0
  131. data/lib/super_diff/rspec/inspection_tree_builders/instance_of.rb +25 -0
  132. data/lib/super_diff/rspec/inspection_tree_builders/kind_of.rb +25 -0
  133. data/lib/super_diff/rspec/inspection_tree_builders/object_having_attributes.rb +34 -0
  134. data/lib/super_diff/rspec/inspection_tree_builders/primitive.rb +9 -0
  135. data/lib/super_diff/rspec/inspection_tree_builders/value_within.rb +30 -0
  136. data/lib/super_diff/rspec/inspection_tree_builders.rb +40 -0
  137. data/lib/super_diff/rspec/object_inspection.rb +14 -4
  138. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +4 -4
  139. data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +1 -1
  140. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +1 -1
  141. data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +2 -2
  142. data/lib/super_diff/rspec.rb +20 -18
  143. data/lib/super_diff/version.rb +1 -1
  144. data/lib/super_diff.rb +69 -21
  145. data/spec/examples.txt +704 -543
  146. data/spec/support/integration/helpers.rb +4 -1
  147. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +1 -1
  148. data/spec/support/models/active_record/person.rb +8 -1
  149. data/spec/support/shared_examples/active_record.rb +5 -5
  150. data/spec/support/unit/helpers.rb +12 -1
  151. data/spec/support/unit/matchers/be_deprecated_in_favor_of.rb +39 -0
  152. data/spec/unit/active_record/object_inspection_spec.rb +5 -5
  153. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/array_spec.rb +8 -8
  154. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/custom_object_spec.rb +9 -9
  155. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/default_object_spec.rb +9 -9
  156. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/hash_spec.rb +8 -8
  157. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/multiline_string_spec.rb +4 -4
  158. data/spec/unit/{helpers_spec.rb → core/helpers_spec.rb} +2 -2
  159. data/spec/unit/{tiered_lines_elider_spec.rb → core/tiered_lines_elider_spec.rb} +2 -2
  160. data/spec/unit/{tiered_lines_formatter_spec.rb → core/tiered_lines_formatter_spec.rb} +1 -1
  161. data/spec/unit/deprecations_spec.rb +176 -0
  162. data/spec/unit/equality_matchers/main_spec.rb +5 -5
  163. data/super_diff.gemspec +6 -0
  164. metadata +127 -115
  165. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +0 -51
  166. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +0 -36
  167. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +0 -16
  168. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +0 -46
  169. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb +0 -46
  170. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +0 -16
  171. data/lib/super_diff/colorized_document_extensions.rb +0 -18
  172. data/lib/super_diff/configuration.rb +0 -149
  173. data/lib/super_diff/diff_formatters/collection.rb +0 -132
  174. data/lib/super_diff/diff_formatters/multiline_string.rb +0 -31
  175. data/lib/super_diff/differs/array.rb +0 -15
  176. data/lib/super_diff/differs/custom_object.rb +0 -17
  177. data/lib/super_diff/differs/date_like.rb +0 -15
  178. data/lib/super_diff/differs/default_object.rb +0 -19
  179. data/lib/super_diff/differs/defaults.rb +0 -13
  180. data/lib/super_diff/differs/empty.rb +0 -13
  181. data/lib/super_diff/differs/hash.rb +0 -15
  182. data/lib/super_diff/differs/main.rb +0 -31
  183. data/lib/super_diff/differs/multiline_string.rb +0 -16
  184. data/lib/super_diff/differs/time_like.rb +0 -15
  185. data/lib/super_diff/gem_version.rb +0 -45
  186. data/lib/super_diff/helpers.rb +0 -86
  187. data/lib/super_diff/implementation_checks.rb +0 -19
  188. data/lib/super_diff/line.rb +0 -83
  189. data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +0 -27
  190. data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +0 -15
  191. data/lib/super_diff/object_inspection/inspection_tree_builders/main.rb +0 -30
  192. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +0 -48
  193. data/lib/super_diff/object_inspection/nodes.rb +0 -50
  194. data/lib/super_diff/object_inspection/prefix_for_next_node.rb +0 -6
  195. data/lib/super_diff/object_inspection/prelude_for_next_node.rb +0 -6
  196. data/lib/super_diff/operation_tree_builders/array.rb +0 -107
  197. data/lib/super_diff/operation_tree_builders/custom_object.rb +0 -40
  198. data/lib/super_diff/operation_tree_builders/date_like.rb +0 -15
  199. data/lib/super_diff/operation_tree_builders/default_object.rb +0 -119
  200. data/lib/super_diff/operation_tree_builders/defaults.rb +0 -5
  201. data/lib/super_diff/operation_tree_builders/hash.rb +0 -218
  202. data/lib/super_diff/operation_tree_builders/multiline_string.rb +0 -86
  203. data/lib/super_diff/operation_tree_builders/time_like.rb +0 -24
  204. data/lib/super_diff/operation_tree_flatteners/array.rb +0 -15
  205. data/lib/super_diff/operation_tree_flatteners/collection.rb +0 -136
  206. data/lib/super_diff/operation_tree_flatteners/custom_object.rb +0 -28
  207. data/lib/super_diff/operation_tree_flatteners/default_object.rb +0 -31
  208. data/lib/super_diff/operation_tree_flatteners/hash.rb +0 -33
  209. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +0 -18
  210. data/lib/super_diff/operation_trees/array.rb +0 -15
  211. data/lib/super_diff/operation_trees/custom_object.rb +0 -15
  212. data/lib/super_diff/operation_trees/default_object.rb +0 -40
  213. data/lib/super_diff/operation_trees/defaults.rb +0 -5
  214. data/lib/super_diff/operation_trees/hash.rb +0 -15
  215. data/lib/super_diff/operation_trees/main.rb +0 -35
  216. data/lib/super_diff/operation_trees/multiline_string.rb +0 -15
  217. data/lib/super_diff/recursion_guard.rb +0 -50
  218. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb +0 -36
  219. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +0 -42
  220. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +0 -102
  221. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher.rb +0 -19
  222. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +0 -42
  223. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +0 -27
  224. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +0 -27
  225. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +0 -36
  226. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/primitive.rb +0 -10
  227. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +0 -32
  228. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +0 -48
  229. data/lib/super_diff/tiered_lines.rb +0 -4
  230. data/lib/super_diff/tiered_lines_elider.rb +0 -462
  231. data/lib/super_diff/tiered_lines_formatter.rb +0 -75
@@ -1,45 +0,0 @@
1
- module SuperDiff
2
- class GemVersion
3
- def initialize(version)
4
- @version = Gem::Version.new(version.to_s)
5
- end
6
-
7
- def <(other)
8
- compare?(:<, other)
9
- end
10
-
11
- def <=(other)
12
- compare?(:<=, other)
13
- end
14
-
15
- def ==(other)
16
- compare?(:==, other)
17
- end
18
-
19
- def >=(other)
20
- compare?(:>=, other)
21
- end
22
-
23
- def >(other)
24
- compare?(:>, other)
25
- end
26
-
27
- def =~(other)
28
- Gem::Requirement.new(other).satisfied_by?(version)
29
- end
30
-
31
- def to_s
32
- version.to_s
33
- end
34
-
35
- private
36
-
37
- attr_reader :version
38
-
39
- def compare?(operator, other_version)
40
- Gem::Requirement.new("#{operator} #{other_version}").satisfied_by?(
41
- version
42
- )
43
- end
44
- end
45
- end
@@ -1,86 +0,0 @@
1
- module SuperDiff
2
- module Helpers
3
- extend self
4
-
5
- # TODO: Simplify this
6
- def style(*args, color_enabled: true, **opts, &block)
7
- klass =
8
- if color_enabled && Csi.color_enabled?
9
- Csi::ColorizedDocument
10
- else
11
- Csi::UncolorizedDocument
12
- end
13
-
14
- document = klass.new.extend(ColorizedDocumentExtensions)
15
-
16
- if block
17
- document.__send__(:evaluate_block, &block)
18
- else
19
- document.colorize(*args, **opts)
20
- end
21
-
22
- document
23
- end
24
-
25
- def plural_type_for(value)
26
- case value
27
- when Numeric
28
- "numbers"
29
- when String
30
- "strings"
31
- when Symbol
32
- "symbols"
33
- else
34
- "objects"
35
- end
36
- end
37
-
38
- def jruby?
39
- defined?(JRUBY_VERSION)
40
- end
41
-
42
- def ruby_version_matches?(version_string)
43
- Gem::Requirement.new(version_string).satisfied_by?(
44
- Gem::Version.new(RUBY_VERSION)
45
- )
46
- end
47
-
48
- if jruby?
49
- def object_address_for(object)
50
- # Source: <https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/RubyBasicObject.java>
51
- "0x%x" % object.hash
52
- end
53
- elsif ruby_version_matches?(">= 2.7.0")
54
- require "json"
55
- require "objspace"
56
-
57
- def object_address_for(object)
58
- # Sources: <https://bugs.ruby-lang.org/issues/15408> and <https://bugs.ruby-lang.org/issues/15626#Object-ID>
59
- json = JSON.parse(ObjectSpace.dump(object))
60
- json.is_a?(Hash) ? "0x%016x" % Integer(json["address"], 16) : ""
61
- end
62
- else
63
- def object_address_for(object)
64
- "0x%016x" % (object.object_id * 2)
65
- end
66
- end
67
-
68
- def with_slice_of_array_replaced(array, range, replacement)
69
- beginning =
70
- if range.begin > 0
71
- array[Range.new(0, range.begin - 1)]
72
- else
73
- []
74
- end
75
-
76
- ending =
77
- if range.end <= array.length - 1
78
- array[Range.new(range.end + 1, array.length - 1)]
79
- else
80
- []
81
- end
82
-
83
- beginning + [replacement] + ending
84
- end
85
- end
86
- end
@@ -1,19 +0,0 @@
1
- module SuperDiff
2
- module ImplementationChecks
3
- protected def unimplemented_instance_method!
4
- raise(
5
- NotImplementedError,
6
- "#{self.class} must implement ##{caller_locations(1, 1).first.label}",
7
- caller(1)
8
- )
9
- end
10
-
11
- protected def unimplemented_class_method!
12
- raise(
13
- NotImplementedError,
14
- "#{self} must implement .#{caller_locations(1, 1).first.label}",
15
- caller(1)
16
- )
17
- end
18
- end
19
- end
@@ -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