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,36 +0,0 @@
1
- module SuperDiff
2
- module ActiveRecord
3
- module ObjectInspection
4
- module InspectionTreeBuilders
5
- class ActiveRecordRelation < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
6
- def self.applies_to?(value)
7
- value.is_a?(::ActiveRecord::Relation)
8
- end
9
-
10
- def call
11
- SuperDiff::ObjectInspection::InspectionTree.new do |t1|
12
- # stree-ignore
13
- t1.as_lines_when_rendering_to_lines(
14
- collection_bookend: :open
15
- ) do |t2|
16
- t2.add_text "#<ActiveRecord::Relation ["
17
- end
18
-
19
- # stree-ignore
20
- t1.nested do |t2|
21
- t2.insert_array_inspection_of(object)
22
- end
23
-
24
- # stree-ignore
25
- t1.as_lines_when_rendering_to_lines(
26
- collection_bookend: :close
27
- ) do |t2|
28
- t2.add_text "]>"
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,16 +0,0 @@
1
- module SuperDiff
2
- module ActiveRecord
3
- module ObjectInspection
4
- module InspectionTreeBuilders
5
- autoload(
6
- :ActiveRecordModel,
7
- "super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model"
8
- )
9
- autoload(
10
- :ActiveRecordRelation,
11
- "super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation"
12
- )
13
- end
14
- end
15
- end
16
- end
@@ -1,46 +0,0 @@
1
- module SuperDiff
2
- module ActiveSupport
3
- module ObjectInspection
4
- module InspectionTreeBuilders
5
- class HashWithIndifferentAccess < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
6
- def self.applies_to?(value)
7
- value.is_a?(::HashWithIndifferentAccess)
8
- end
9
-
10
- def call
11
- SuperDiff::ObjectInspection::InspectionTree.new do |t1|
12
- # stree-ignore
13
- t1.as_lines_when_rendering_to_lines(
14
- collection_bookend: :open
15
- ) do |t2|
16
- t2.add_text "#<HashWithIndifferentAccess {"
17
- end
18
-
19
- # stree-ignore
20
- t1.when_rendering_to_string do |t2|
21
- t2.add_text " "
22
- end
23
-
24
- # stree-ignore
25
- t1.nested do |t2|
26
- t2.insert_hash_inspection_of(object)
27
- end
28
-
29
- # stree-ignore
30
- t1.when_rendering_to_string do |t2|
31
- t2.add_text " "
32
- end
33
-
34
- # stree-ignore
35
- t1.as_lines_when_rendering_to_lines(
36
- collection_bookend: :close
37
- ) do |t2|
38
- t2.add_text "}>"
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,46 +0,0 @@
1
- module SuperDiff
2
- module ActiveSupport
3
- module ObjectInspection
4
- module InspectionTreeBuilders
5
- class OrderedOptions < SuperDiff::ObjectInspection::InspectionTreeBuilders::Hash
6
- def self.applies_to?(value)
7
- value.is_a?(::ActiveSupport::OrderedOptions)
8
- end
9
-
10
- def call
11
- SuperDiff::ObjectInspection::InspectionTree.new do |t1|
12
- # stree-ignore
13
- t1.as_lines_when_rendering_to_lines(
14
- collection_bookend: :open
15
- ) do |t2|
16
- t2.add_text "#<OrderedOptions {"
17
- end
18
-
19
- # stree-ignore
20
- t1.when_rendering_to_string do |t2|
21
- t2.add_text " "
22
- end
23
-
24
- # stree-ignore
25
- t1.nested do |t2|
26
- t2.insert_hash_inspection_of(object.to_hash)
27
- end
28
-
29
- # stree-ignore
30
- t1.when_rendering_to_string do |t2|
31
- t2.add_text " "
32
- end
33
-
34
- # stree-ignore
35
- t1.as_lines_when_rendering_to_lines(
36
- collection_bookend: :close
37
- ) do |t2|
38
- t2.add_text "}>"
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,16 +0,0 @@
1
- module SuperDiff
2
- module ActiveSupport
3
- module ObjectInspection
4
- module InspectionTreeBuilders
5
- autoload(
6
- :HashWithIndifferentAccess,
7
- "super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access"
8
- )
9
- autoload(
10
- :OrderedOptions,
11
- "super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options"
12
- )
13
- end
14
- end
15
- end
16
- end
@@ -1,18 +0,0 @@
1
- module SuperDiff
2
- module ColorizedDocumentExtensions
3
- def self.extended(extendee)
4
- extendee.singleton_class.class_eval { alias_method :normal, :text }
5
- end
6
-
7
- %i[actual border elision_marker expected header].each do |method_name|
8
- define_method(method_name) do |*args, **opts, &block|
9
- colorize(
10
- *args,
11
- **opts,
12
- fg: SuperDiff.configuration.public_send("#{method_name}_color"),
13
- &block
14
- )
15
- end
16
- end
17
- end
18
- end
@@ -1,149 +0,0 @@
1
- module SuperDiff
2
- class Configuration
3
- attr_reader(
4
- :extra_diff_formatter_classes,
5
- :extra_differ_classes,
6
- :extra_inspection_tree_builder_classes,
7
- :extra_operation_tree_builder_classes,
8
- :extra_operation_tree_classes
9
- )
10
- attr_accessor(
11
- :actual_color,
12
- :border_color,
13
- :color_enabled,
14
- :diff_elision_enabled,
15
- :diff_elision_maximum,
16
- :elision_marker_color,
17
- :expected_color,
18
- :header_color,
19
- :key_enabled
20
- )
21
-
22
- def initialize(options = {})
23
- @actual_color = :yellow
24
- @border_color = :blue
25
- @color_enabled = color_enabled_by_default?
26
- @diff_elision_enabled = false
27
- @diff_elision_maximum = 0
28
- @elision_marker_color = :cyan
29
- @expected_color = :magenta
30
- @extra_diff_formatter_classes = [].freeze
31
- @extra_differ_classes = [].freeze
32
- @extra_inspection_tree_builder_classes = [].freeze
33
- @extra_operation_tree_builder_classes = [].freeze
34
- @extra_operation_tree_classes = [].freeze
35
- @header_color = :white
36
- @key_enabled = true
37
-
38
- merge!(options)
39
- end
40
-
41
- def initialize_dup(original)
42
- super
43
- @extra_differ_classes = original.extra_differ_classes.dup.freeze
44
- @extra_operation_tree_builder_classes =
45
- original.extra_operation_tree_builder_classes.dup.freeze
46
- @extra_operation_tree_classes =
47
- original.extra_operation_tree_classes.dup.freeze
48
- @extra_inspection_tree_builder_classes =
49
- original.extra_inspection_tree_builder_classes.dup.freeze
50
- end
51
-
52
- def color_enabled?
53
- @color_enabled
54
- end
55
-
56
- def diff_elision_enabled?
57
- @diff_elision_enabled
58
- end
59
-
60
- def key_enabled?
61
- @key_enabled
62
- end
63
-
64
- def merge!(configuration_or_options)
65
- options =
66
- if configuration_or_options.is_a?(self.class)
67
- configuration_or_options.to_h
68
- else
69
- configuration_or_options
70
- end
71
-
72
- options.each { |key, value| instance_variable_set("@#{key}", value) }
73
-
74
- updated
75
- end
76
-
77
- def updated
78
- SuperDiff::Csi.color_enabled = color_enabled?
79
- end
80
-
81
- def add_extra_diff_formatter_classes(*classes)
82
- @extra_diff_formatter_classes =
83
- (@extra_diff_formatter_classes + classes).freeze
84
- end
85
- alias_method(
86
- :add_extra_diff_formatter_class,
87
- :add_extra_diff_formatter_classes
88
- )
89
-
90
- def add_extra_differ_classes(*classes)
91
- @extra_differ_classes = (@extra_differ_classes + classes).freeze
92
- end
93
- alias_method :add_extra_differ_class, :add_extra_differ_classes
94
-
95
- def add_extra_inspection_tree_builder_classes(*classes)
96
- @extra_inspection_tree_builder_classes =
97
- (@extra_inspection_tree_builder_classes + classes).freeze
98
- end
99
- alias_method(
100
- :add_extra_inspection_tree_builder_class,
101
- :add_extra_inspection_tree_builder_classes
102
- )
103
-
104
- def add_extra_operation_tree_builder_classes(*classes)
105
- @extra_operation_tree_builder_classes =
106
- (@extra_operation_tree_builder_classes + classes).freeze
107
- end
108
- alias_method(
109
- :add_extra_operation_tree_builder_class,
110
- :add_extra_operation_tree_builder_classes
111
- )
112
-
113
- def add_extra_operation_tree_classes(*classes)
114
- @extra_operation_tree_classes =
115
- (@extra_operation_tree_classes + classes).freeze
116
- end
117
- alias_method(
118
- :add_extra_operation_tree_class,
119
- :add_extra_operation_tree_classes
120
- )
121
-
122
- def to_h
123
- {
124
- actual_color: actual_color,
125
- border_color: border_color,
126
- color_enabled: color_enabled?,
127
- diff_elision_enabled: diff_elision_enabled?,
128
- diff_elision_maximum: diff_elision_maximum,
129
- elision_marker_color: elision_marker_color,
130
- expected_color: expected_color,
131
- extra_diff_formatter_classes: extra_diff_formatter_classes.dup,
132
- extra_differ_classes: extra_differ_classes.dup,
133
- extra_inspection_tree_builder_classes:
134
- extra_inspection_tree_builder_classes.dup,
135
- extra_operation_tree_builder_classes:
136
- extra_operation_tree_builder_classes.dup,
137
- extra_operation_tree_classes: extra_operation_tree_classes.dup,
138
- header_color: header_color,
139
- key_enabled: key_enabled?
140
- }
141
- end
142
-
143
- private
144
-
145
- def color_enabled_by_default?
146
- ENV["CI"] == "true" || $stdout.respond_to?(:tty?) && $stdout.tty?
147
- end
148
- end
149
- end
@@ -1,132 +0,0 @@
1
- module SuperDiff
2
- module DiffFormatters
3
- class Collection
4
- extend AttrExtras.mixin
5
-
6
- ICONS = { delete: "-", insert: "+" }.freeze
7
- STYLES = { insert: :actual, delete: :expected, noop: :plain }.freeze
8
-
9
- method_object(
10
- %i[
11
- open_token!
12
- close_token!
13
- operation_tree!
14
- indent_level!
15
- add_comma!
16
- collection_prefix!
17
- build_item_prefix!
18
- ]
19
- )
20
-
21
- def call
22
- lines.join("\n")
23
- end
24
-
25
- private
26
-
27
- attr_query :add_comma?
28
-
29
- def lines
30
- [
31
- " #{indentation}#{collection_prefix}#{open_token}",
32
- *contents,
33
- " #{indentation}#{close_token}#{comma}"
34
- ]
35
- end
36
-
37
- def contents
38
- operation_tree.map do |operation|
39
- if operation.name == :change
40
- handle_change_operation(operation)
41
- else
42
- handle_non_change_operation(operation)
43
- end
44
- end
45
- end
46
-
47
- def handle_change_operation(operation)
48
- SuperDiff::RecursionGuard.guarding_recursion_of(
49
- operation.left_collection,
50
- operation.right_collection
51
- ) do |already_seen|
52
- if already_seen
53
- raise "Infinite recursion!"
54
- else
55
- operation.child_operations.to_diff(
56
- indent_level: indent_level + 1,
57
- collection_prefix: build_item_prefix.call(operation),
58
- add_comma: operation.should_add_comma_after_displaying?
59
- )
60
- end
61
- end
62
- end
63
-
64
- def handle_non_change_operation(operation)
65
- icon = ICONS.fetch(operation.name, " ")
66
- style_name = STYLES.fetch(operation.name, :normal)
67
- chunk =
68
- build_chunk_for(
69
- operation,
70
- prefix: build_item_prefix.call(operation),
71
- icon: icon
72
- )
73
-
74
- chunk << "," if operation.should_add_comma_after_displaying?
75
-
76
- style_chunk(style_name, chunk)
77
- end
78
-
79
- def build_chunk_for(operation, prefix:, icon:)
80
- if operation.value.equal?(operation.collection)
81
- build_chunk_from_string(
82
- SuperDiff::RecursionGuard::PLACEHOLDER,
83
- prefix: build_item_prefix.call(operation),
84
- icon: icon
85
- )
86
- else
87
- build_chunk_by_inspecting(
88
- operation.value,
89
- prefix: build_item_prefix.call(operation),
90
- icon: icon
91
- )
92
- end
93
- end
94
-
95
- def build_chunk_by_inspecting(value, prefix:, icon:)
96
- inspection = SuperDiff.inspect_object(value, as_single_line: false)
97
- build_chunk_from_string(inspection, prefix: prefix, icon: icon)
98
- end
99
-
100
- def build_chunk_from_string(value, prefix:, icon:)
101
- value
102
- .split("\n")
103
- .map
104
- .with_index do |line, index|
105
- [
106
- icon,
107
- " ",
108
- indentation(offset: 1),
109
- (index == 0 ? prefix : ""),
110
- line
111
- ].join
112
- end
113
- .join("\n")
114
- end
115
-
116
- def style_chunk(style_name, chunk)
117
- chunk
118
- .split("\n")
119
- .map { |line| Helpers.style(style_name, line) }
120
- .join("\n")
121
- end
122
-
123
- def indentation(offset: 0)
124
- " " * (indent_level + offset)
125
- end
126
-
127
- def comma
128
- add_comma? ? "," : ""
129
- end
130
- end
131
- end
132
- end
@@ -1,31 +0,0 @@
1
- module SuperDiff
2
- module DiffFormatters
3
- class MultilineString < Base
4
- def self.applies_to?(operation_tree)
5
- operation_tree.is_a?(OperationTrees::MultilineString)
6
- end
7
-
8
- def call
9
- lines.join("\n")
10
- end
11
-
12
- private
13
-
14
- def lines
15
- operation_tree.reduce([]) do |array, operation|
16
- case operation.name
17
- when :change
18
- array << Helpers.style(:expected, "- #{operation.left_value}")
19
- array << Helpers.style(:actual, "+ #{operation.right_value}")
20
- when :delete
21
- array << Helpers.style(:expected, "- #{operation.value}")
22
- when :insert
23
- array << Helpers.style(:actual, "+ #{operation.value}")
24
- else
25
- array << Helpers.style(:plain, " #{operation.value}")
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,15 +0,0 @@
1
- module SuperDiff
2
- module Differs
3
- class Array < Base
4
- def self.applies_to?(expected, actual)
5
- expected.is_a?(::Array) && actual.is_a?(::Array)
6
- end
7
-
8
- protected
9
-
10
- def operation_tree_builder_class
11
- OperationTreeBuilders::Array
12
- end
13
- end
14
- end
15
- end
@@ -1,17 +0,0 @@
1
- module SuperDiff
2
- module Differs
3
- class CustomObject < Base
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 operation_tree_builder_class
13
- OperationTreeBuilders::CustomObject
14
- end
15
- end
16
- end
17
- end
@@ -1,15 +0,0 @@
1
- module SuperDiff
2
- module Differs
3
- class DateLike < Base
4
- def self.applies_to?(expected, actual)
5
- SuperDiff.date_like?(expected) && SuperDiff.date_like?(actual)
6
- end
7
-
8
- protected
9
-
10
- def operation_tree_builder_class
11
- OperationTreeBuilders::DateLike
12
- end
13
- end
14
- end
15
- end
@@ -1,19 +0,0 @@
1
- module SuperDiff
2
- module Differs
3
- class DefaultObject < Base
4
- def self.applies_to?(expected, actual)
5
- expected.class == actual.class
6
- end
7
-
8
- protected
9
-
10
- def operation_tree
11
- OperationTreeBuilders::Main.call(
12
- expected: expected,
13
- actual: actual,
14
- all_or_nothing: true
15
- )
16
- end
17
- end
18
- end
19
- end
@@ -1,13 +0,0 @@
1
- module SuperDiff
2
- module Differs
3
- DEFAULTS = [
4
- Array,
5
- Hash,
6
- TimeLike,
7
- DateLike,
8
- MultilineString,
9
- CustomObject,
10
- DefaultObject
11
- ].freeze
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- module SuperDiff
2
- module Differs
3
- class Empty < Base
4
- def self.applies_to?(_expected, _actual)
5
- true
6
- end
7
-
8
- def call
9
- ""
10
- end
11
- end
12
- end
13
- end
@@ -1,15 +0,0 @@
1
- module SuperDiff
2
- module Differs
3
- class Hash < Base
4
- def self.applies_to?(expected, actual)
5
- expected.is_a?(::Hash) && actual.is_a?(::Hash)
6
- end
7
-
8
- protected
9
-
10
- def operation_tree_builder_class
11
- OperationTreeBuilders::Hash
12
- end
13
- end
14
- end
15
- end
@@ -1,31 +0,0 @@
1
- module SuperDiff
2
- module Differs
3
- class Main
4
- extend AttrExtras.mixin
5
-
6
- method_object(:expected, :actual, [indent_level: 0, omit_empty: false])
7
-
8
- def call
9
- if resolved_class
10
- resolved_class.call(expected, actual, indent_level: indent_level)
11
- else
12
- raise Errors::NoDifferAvailableError.create(expected, actual)
13
- end
14
- end
15
-
16
- private
17
-
18
- attr_query :omit_empty?
19
-
20
- def resolved_class
21
- available_classes.find { |klass| klass.applies_to?(expected, actual) }
22
- end
23
-
24
- def available_classes
25
- classes = SuperDiff.configuration.extra_differ_classes + DEFAULTS
26
-
27
- omit_empty? ? classes : classes + [Empty]
28
- end
29
- end
30
- end
31
- end
@@ -1,16 +0,0 @@
1
- module SuperDiff
2
- module Differs
3
- class MultilineString < Base
4
- def self.applies_to?(expected, actual)
5
- expected.is_a?(::String) && actual.is_a?(::String) &&
6
- (expected.include?("\n") || actual.include?("\n"))
7
- end
8
-
9
- protected
10
-
11
- def operation_tree_builder_class
12
- OperationTreeBuilders::MultilineString
13
- end
14
- end
15
- end
16
- end
@@ -1,15 +0,0 @@
1
- module SuperDiff
2
- module Differs
3
- class TimeLike < Base
4
- def self.applies_to?(expected, actual)
5
- SuperDiff.time_like?(expected) && SuperDiff.time_like?(actual)
6
- end
7
-
8
- protected
9
-
10
- def operation_tree_builder_class
11
- OperationTreeBuilders::TimeLike
12
- end
13
- end
14
- end
15
- end