super_diff 0.5.3 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +46 -20
  3. data/lib/super_diff.rb +46 -7
  4. data/lib/super_diff/active_record.rb +7 -7
  5. data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -13
  6. data/lib/super_diff/active_record/object_inspection.rb +2 -6
  7. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +16 -0
  8. data/lib/super_diff/active_record/object_inspection/{inspectors → inspection_tree_builders}/active_record_model.rb +19 -20
  9. data/lib/super_diff/active_record/object_inspection/{inspectors → inspection_tree_builders}/active_record_relation.rb +9 -8
  10. data/lib/super_diff/active_record/operation_tree_flatteners.rb +10 -0
  11. data/lib/super_diff/active_record/operation_tree_flatteners/active_record_relation.rb +17 -0
  12. data/lib/super_diff/active_record/operation_trees/active_record_relation.rb +8 -7
  13. data/lib/super_diff/active_support.rb +8 -8
  14. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -13
  15. data/lib/super_diff/active_support/object_inspection.rb +2 -6
  16. data/lib/super_diff/active_support/object_inspection/{inspectors.rb → inspection_tree_builders.rb} +2 -2
  17. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +37 -0
  18. data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +17 -0
  19. data/lib/super_diff/active_support/operation_tree_flatteners.rb +10 -0
  20. data/lib/super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access.rb +17 -0
  21. data/lib/super_diff/active_support/operation_trees/hash_with_indifferent_access.rb +4 -7
  22. data/lib/super_diff/colorized_document_extensions.rb +9 -6
  23. data/lib/super_diff/configuration.rb +102 -19
  24. data/lib/super_diff/csi.rb +1 -1
  25. data/lib/super_diff/csi/four_bit_color.rb +0 -2
  26. data/lib/super_diff/diff_formatters/collection.rb +2 -2
  27. data/lib/super_diff/diff_formatters/multiline_string.rb +4 -4
  28. data/lib/super_diff/differs/array.rb +1 -1
  29. data/lib/super_diff/differs/base.rb +3 -21
  30. data/lib/super_diff/differs/custom_object.rb +1 -1
  31. data/lib/super_diff/differs/default_object.rb +1 -1
  32. data/lib/super_diff/differs/hash.rb +1 -1
  33. data/lib/super_diff/differs/main.rb +1 -7
  34. data/lib/super_diff/differs/multiline_string.rb +1 -1
  35. data/lib/super_diff/differs/time_like.rb +1 -1
  36. data/lib/super_diff/equality_matchers/array.rb +4 -4
  37. data/lib/super_diff/equality_matchers/default.rb +4 -4
  38. data/lib/super_diff/equality_matchers/hash.rb +4 -4
  39. data/lib/super_diff/equality_matchers/multiline_string.rb +4 -4
  40. data/lib/super_diff/equality_matchers/primitive.rb +6 -9
  41. data/lib/super_diff/equality_matchers/singleline_string.rb +4 -4
  42. data/lib/super_diff/gem_version.rb +45 -0
  43. data/lib/super_diff/helpers.rb +52 -2
  44. data/lib/super_diff/line.rb +83 -0
  45. data/lib/super_diff/object_inspection.rb +12 -9
  46. data/lib/super_diff/object_inspection/inspection_tree.rb +183 -81
  47. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +44 -0
  48. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +38 -0
  49. data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +27 -0
  50. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +37 -0
  51. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +63 -0
  52. data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/defaults.rb +1 -2
  53. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +46 -0
  54. data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/main.rb +5 -10
  55. data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +21 -0
  56. data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +64 -0
  57. data/lib/super_diff/object_inspection/nodes.rb +33 -32
  58. data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +97 -0
  59. data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +27 -0
  60. data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +27 -0
  61. data/lib/super_diff/object_inspection/nodes/as_single_line.rb +33 -0
  62. data/lib/super_diff/object_inspection/nodes/base.rb +55 -20
  63. data/lib/super_diff/object_inspection/nodes/inspection.rb +47 -7
  64. data/lib/super_diff/object_inspection/nodes/nesting.rb +16 -5
  65. data/lib/super_diff/object_inspection/nodes/only_when.rb +54 -0
  66. data/lib/super_diff/object_inspection/nodes/text.rb +16 -2
  67. data/lib/super_diff/object_inspection/nodes/when_empty.rb +21 -6
  68. data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +20 -5
  69. data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +27 -0
  70. data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +27 -0
  71. data/lib/super_diff/object_inspection/prefix_for_next_node.rb +6 -0
  72. data/lib/super_diff/object_inspection/prelude_for_next_node.rb +6 -0
  73. data/lib/super_diff/operation_tree_builders/array.rb +7 -10
  74. data/lib/super_diff/operation_tree_builders/base.rb +6 -6
  75. data/lib/super_diff/operation_tree_builders/custom_object.rb +5 -2
  76. data/lib/super_diff/operation_tree_builders/default_object.rb +1 -1
  77. data/lib/super_diff/operation_tree_builders/defaults.rb +1 -1
  78. data/lib/super_diff/operation_tree_builders/hash.rb +1 -8
  79. data/lib/super_diff/operation_tree_builders/multiline_string.rb +2 -6
  80. data/lib/super_diff/operation_tree_builders/time_like.rb +2 -2
  81. data/lib/super_diff/operation_tree_flatteners.rb +20 -0
  82. data/lib/super_diff/operation_tree_flatteners/array.rb +15 -0
  83. data/lib/super_diff/operation_tree_flatteners/base.rb +54 -0
  84. data/lib/super_diff/operation_tree_flatteners/collection.rb +139 -0
  85. data/lib/super_diff/operation_tree_flatteners/custom_object.rb +28 -0
  86. data/lib/super_diff/operation_tree_flatteners/default_object.rb +32 -0
  87. data/lib/super_diff/operation_tree_flatteners/hash.rb +41 -0
  88. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +17 -0
  89. data/lib/super_diff/operation_trees/array.rb +4 -7
  90. data/lib/super_diff/operation_trees/base.rb +39 -16
  91. data/lib/super_diff/operation_trees/custom_object.rb +4 -8
  92. data/lib/super_diff/operation_trees/default_object.rb +28 -13
  93. data/lib/super_diff/operation_trees/hash.rb +4 -7
  94. data/lib/super_diff/operation_trees/main.rb +1 -1
  95. data/lib/super_diff/operation_trees/multiline_string.rb +4 -7
  96. data/lib/super_diff/operations/binary_operation.rb +1 -6
  97. data/lib/super_diff/operations/unary_operation.rb +2 -30
  98. data/lib/super_diff/recursion_guard.rb +3 -3
  99. data/lib/super_diff/rspec.rb +41 -13
  100. data/lib/super_diff/rspec/differs/collection_including.rb +4 -2
  101. data/lib/super_diff/rspec/differs/hash_including.rb +4 -2
  102. data/lib/super_diff/rspec/matcher_text_builders/base.rb +7 -7
  103. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +6 -6
  104. data/lib/super_diff/rspec/matcher_text_builders/contain_exactly.rb +1 -1
  105. data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +4 -4
  106. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +1 -1
  107. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +5 -5
  108. data/lib/super_diff/rspec/monkey_patches.rb +353 -306
  109. data/lib/super_diff/rspec/object_inspection.rb +4 -1
  110. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +44 -0
  111. data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/collection_containing_exactly.rb +9 -8
  112. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +34 -0
  113. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +103 -0
  114. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +36 -0
  115. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +26 -0
  116. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +26 -0
  117. data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/object_having_attributes.rb +10 -12
  118. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/primitive.rb +10 -0
  119. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +33 -0
  120. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +12 -4
  121. data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +10 -3
  122. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +10 -3
  123. data/lib/super_diff/tiered_lines.rb +4 -0
  124. data/lib/super_diff/tiered_lines_elider.rb +490 -0
  125. data/lib/super_diff/tiered_lines_formatter.rb +79 -0
  126. data/lib/super_diff/version.rb +1 -1
  127. data/spec/examples.txt +407 -5
  128. data/spec/integration/rails/active_support_spec.rb +19 -0
  129. data/spec/integration/rspec/be_falsey_matcher_spec.rb +10 -10
  130. data/spec/integration/rspec/be_matcher_spec.rb +100 -100
  131. data/spec/integration/rspec/be_nil_matcher_spec.rb +10 -10
  132. data/spec/integration/rspec/be_predicate_matcher_spec.rb +103 -103
  133. data/spec/integration/rspec/be_truthy_matcher_spec.rb +10 -10
  134. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +113 -107
  135. data/spec/integration/rspec/eq_matcher_spec.rb +223 -277
  136. data/spec/integration/rspec/have_attributes_matcher_spec.rb +138 -129
  137. data/spec/integration/rspec/have_predicate_matcher_spec.rb +65 -65
  138. data/spec/integration/rspec/include_matcher_spec.rb +73 -73
  139. data/spec/integration/rspec/match_array_matcher_spec.rb +126 -119
  140. data/spec/integration/rspec/match_matcher_spec.rb +362 -274
  141. data/spec/integration/rspec/raise_error_matcher_spec.rb +86 -86
  142. data/spec/integration/rspec/respond_to_matcher_spec.rb +240 -240
  143. data/spec/integration/rspec/third_party_matcher_spec.rb +8 -8
  144. data/spec/integration/rspec/unhandled_errors_spec.rb +5 -5
  145. data/spec/spec_helper.rb +33 -13
  146. data/spec/support/command_runner.rb +15 -25
  147. data/spec/support/helpers.rb +21 -0
  148. data/spec/support/integration/helpers.rb +8 -2
  149. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +4 -4
  150. data/spec/support/integration/test_programs/base.rb +38 -10
  151. data/spec/support/integration/test_programs/rspec_active_record.rb +1 -1
  152. data/spec/support/integration/test_programs/rspec_active_support.rb +17 -0
  153. data/spec/support/integration/test_programs/rspec_rails.rb +1 -1
  154. data/spec/support/shared_examples/active_record.rb +109 -108
  155. data/spec/support/shared_examples/active_support.rb +65 -0
  156. data/spec/support/shared_examples/elided_diffs.rb +914 -0
  157. data/spec/support/shared_examples/hash_with_indifferent_access.rb +196 -232
  158. data/spec/support/unit/helpers.rb +15 -0
  159. data/spec/support/unit/matchers/match_output.rb +41 -0
  160. data/spec/unit/active_record/object_inspection_spec.rb +273 -0
  161. data/spec/unit/equality_matchers/main_spec.rb +445 -465
  162. data/spec/unit/helpers_spec.rb +61 -0
  163. data/spec/unit/operation_tree_flatteners/array_spec.rb +604 -0
  164. data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +667 -0
  165. data/spec/unit/operation_tree_flatteners/default_object_spec.rb +687 -0
  166. data/spec/unit/operation_tree_flatteners/hash_spec.rb +632 -0
  167. data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +121 -0
  168. data/spec/unit/rspec/object_inspection_spec.rb +446 -0
  169. data/spec/unit/super_diff_spec.rb +1958 -0
  170. data/spec/unit/tiered_lines_elider_spec.rb +6356 -0
  171. data/spec/unit/tiered_lines_formatter_spec.rb +193 -0
  172. data/super_diff.gemspec +1 -1
  173. metadata +95 -50
  174. data/lib/super_diff/active_record/diff_formatters.rb +0 -10
  175. data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +0 -23
  176. data/lib/super_diff/active_record/object_inspection/inspectors.rb +0 -16
  177. data/lib/super_diff/active_support/diff_formatters.rb +0 -10
  178. data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +0 -36
  179. data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +0 -28
  180. data/lib/super_diff/diff_formatters.rb +0 -14
  181. data/lib/super_diff/diff_formatters/array.rb +0 -21
  182. data/lib/super_diff/diff_formatters/base.rb +0 -33
  183. data/lib/super_diff/diff_formatters/custom_object.rb +0 -30
  184. data/lib/super_diff/diff_formatters/default_object.rb +0 -46
  185. data/lib/super_diff/diff_formatters/defaults.rb +0 -10
  186. data/lib/super_diff/diff_formatters/hash.rb +0 -34
  187. data/lib/super_diff/diff_formatters/main.rb +0 -41
  188. data/lib/super_diff/object_inspection/inspectors.rb +0 -23
  189. data/lib/super_diff/object_inspection/inspectors/array.rb +0 -32
  190. data/lib/super_diff/object_inspection/inspectors/base.rb +0 -36
  191. data/lib/super_diff/object_inspection/inspectors/custom_object.rb +0 -37
  192. data/lib/super_diff/object_inspection/inspectors/default_object.rb +0 -61
  193. data/lib/super_diff/object_inspection/inspectors/hash.rb +0 -32
  194. data/lib/super_diff/object_inspection/inspectors/primitive.rb +0 -28
  195. data/lib/super_diff/object_inspection/inspectors/string.rb +0 -23
  196. data/lib/super_diff/object_inspection/inspectors/time_like.rb +0 -23
  197. data/lib/super_diff/object_inspection/nodes/break.rb +0 -15
  198. data/lib/super_diff/object_inspection/nodes/when_multiline.rb +0 -22
  199. data/lib/super_diff/object_inspection/nodes/when_singleline.rb +0 -24
  200. data/lib/super_diff/rspec/object_inspection/inspectors.rb +0 -40
  201. data/lib/super_diff/rspec/object_inspection/inspectors/collection_including.rb +0 -28
  202. data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +0 -31
  203. data/lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb +0 -23
  204. data/lib/super_diff/rspec/object_inspection/inspectors/kind_of.rb +0 -23
  205. data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +0 -13
  206. data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +0 -29
  207. data/spec/support/object_id.rb +0 -27
  208. data/spec/support/ruby_versions.rb +0 -11
  209. data/spec/unit/object_inspection_spec.rb +0 -1168
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5427cb2217992c9dffd57826837caaa750ddcd422625498c3bca9cf40ae8e32
4
- data.tar.gz: 540a3e3ea47bc98c4abf45ff6ff216563f70f1492bb2c06a54525b6414b306ae
3
+ metadata.gz: 7d1ad189acadc1bcdf4ad4e63ca6b9d946b7a66f8d1544887389d7f093153b31
4
+ data.tar.gz: f96fb6488cf55e679b3ce8953c26eea0a5c5c6113c35dc30c7d19eb5e3b65ae2
5
5
  SHA512:
6
- metadata.gz: 1bf06c03ce556532384242e0193628bae55134e3edf65003e1d0b7a1015e25af6f9ce68bd23a7ca2ebadddb0093103a643f9bb742116d2456f20146bb948f380
7
- data.tar.gz: c32489d6915ac9f7fc3cf1c0427683977b3a569a99e36a7d8e47f1209e74efcf3f86b3986b1e40ed51d2321d89f1e8530bdda79352c1d53fd94798370f2261de
6
+ metadata.gz: 5eaeee5249d8cc865ff1fbef12b0c306607bba7f0224ac906c8bbfac0ad4cc196660fed461a3efcbdd69a557cb8dc7aca925351bd9acae5761d4af25d7bac19e
7
+ data.tar.gz: 0bdd31dada209126940d0e55c1a3b0970b1c17b8c22eecb685aa59ea518bb28456b902bd81256a4b13132d3c9ad88cd115dabe1a1796edd90afeee65568a0c74
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # SuperDiff [![Gem Version][version-badge]][rubygems] [![Build Status][travis-badge]][travis] ![Downloads][downloads-badge] [![IssueHunt][issuehunt-badge]][issuehunt]
1
+ # SuperDiff [![Gem Version][version-badge]][rubygems] [![Build Status][gh-actions-badge]][gh-actions] ![Downloads][downloads-badge] [![IssueHunt][issuehunt-badge]][issuehunt]
2
2
 
3
3
  [version-badge]: http://img.shields.io/gem/v/super_diff.svg
4
4
  [rubygems]: http://rubygems.org/gems/super_diff
5
- [travis-badge]: http://img.shields.io/travis/mcmire/super_diff/master.svg
5
+ [gh-actions-badge]: http://img.shields.io/github/workflow/status/mcmire/super_diff/SuperDiff/master
6
6
  [downloads-badge]: http://img.shields.io/gem/dtv/super_diff.svg
7
7
  [hound]: https://houndci.com
8
8
  [issuehunt-badge]: https://img.shields.io/badge/sponsored_through-IssueHunt-2EC28C
@@ -155,30 +155,56 @@ require "super_diff/rspec"
155
155
 
156
156
  ## Configuration
157
157
 
158
- As capable as this library is,
159
- it doesn't know how to deal with every kind of object out there.
160
- If you have a custom class,
161
- and instances of your class aren't appearing in diffs like you like,
162
- you might find it necessary to instruct the gem on how to handle them.
163
- In that case
164
- you would add something like this to your test helper file
165
- (`rails_helper` or `spec_helper`):
158
+ You can customize the behavior of the gem
159
+ by adding a configuration block
160
+ to your test helper file
161
+ (`rails_helper` or `spec_helper`)
162
+ which looks something like this:
163
+
164
+ ``` ruby
165
+ SuperDiff.configure do |config|
166
+ # ...
167
+ end
168
+ ```
169
+
170
+ ### Customizing colors
171
+
172
+ If you don't like the colors that SuperDiff uses,
173
+ you can change them like this:
174
+
175
+ ``` ruby
176
+ SuperDiff.configure do |config|
177
+ config.actual_color = :green
178
+ config.expected_color = :red
179
+ config.border_color = :yellow
180
+ config.header_color = :yellow
181
+ end
182
+ ```
183
+
184
+ See [eight_bit_color.rb](lib/super_diff/csi/eight_bit_color.rb)
185
+ for the list of available colors.
186
+
187
+ ### Diffing custom objects
188
+
189
+ If you are comparing two data structures
190
+ that involve a class that is specific to your project,
191
+ the resulting diff may not look as good as diffs involving native or primitive objects.
192
+ This happens because if SuperDiff doesn't recognize a class,
193
+ it will fall back to a generic representation when diffing instances of that class.
194
+ Fortunately, the gem has a pluggable interface
195
+ that allows you to insert your own implementations
196
+ of key pieces involved in the diffing process.
197
+ I'll have more about how that works soon,
198
+ but here is what such a configuration would look like:
166
199
 
167
200
  ``` ruby
168
201
  SuperDiff.configure do |config|
169
202
  config.add_extra_differ_class(YourDiffer)
170
203
  config.add_extra_operation_tree_builder_class(YourOperationTreeBuilder)
171
204
  config.add_extra_operation_tree_class(YourOperationTree)
172
- config.add_extra_diff_formatter_class(YourDiffFormatter)
173
205
  end
174
206
  ```
175
207
 
176
- *(More info here in the future on adding a custom differ,
177
- operation tree builder,
178
- operation tree,
179
- and diff formatter.
180
- Also explanations on what these are.)*
181
-
182
208
  ## Support
183
209
 
184
210
  My goal for this library is to improve your development experience.
@@ -204,12 +230,12 @@ I'll get notified right away!
204
230
 
205
231
  ## Compatibility
206
232
 
207
- `super_diff` is [tested][travis] to work with
233
+ `super_diff` is [tested][gh-actions] to work with
208
234
  Ruby >= 2.5.x,
209
235
  RSpec 3.x,
210
236
  and Rails >= 5.x.
211
237
 
212
- [travis]: http://travis-ci.org/mcmire/super_diff
238
+ [gh-actions]: https://github.com/mcmire/super_diff/actions?query=workflow%3ASuperDiff
213
239
 
214
240
  ## Inspiration/Thanks
215
241
 
@@ -232,5 +258,5 @@ Thank you to the authors of these libraries!
232
258
 
233
259
  ## Author/License
234
260
 
235
- `super_diff` was created and is maintained by Elliot Winkler.
261
+ SuperDiff was created and is maintained by Elliot Winkler.
236
262
  It is released under the [MIT license](LICENSE).
data/lib/super_diff.rb CHANGED
@@ -7,39 +7,78 @@ module SuperDiff
7
7
  :ColorizedDocumentExtensions,
8
8
  "super_diff/colorized_document_extensions",
9
9
  )
10
+ autoload :OperationTreeFlatteners, "super_diff/operation_tree_flatteners"
10
11
  autoload :Configuration, "super_diff/configuration"
11
12
  autoload :Csi, "super_diff/csi"
12
13
  autoload :DiffFormatters, "super_diff/diff_formatters"
13
14
  autoload :Differs, "super_diff/differs"
14
15
  autoload :EqualityMatchers, "super_diff/equality_matchers"
15
16
  autoload :Errors, "super_diff/errors"
17
+ autoload :GemVersion, "super_diff/gem_version"
16
18
  autoload :Helpers, "super_diff/helpers"
17
19
  autoload :ImplementationChecks, "super_diff/implementation_checks"
20
+ autoload :Line, "super_diff/line"
21
+ autoload :TieredLines, "super_diff/tiered_lines"
22
+ autoload :TieredLinesElider, "super_diff/tiered_lines_elider"
23
+ autoload :TieredLinesFormatter, "super_diff/tiered_lines_formatter"
18
24
  autoload :ObjectInspection, "super_diff/object_inspection"
19
25
  autoload :OperationTrees, "super_diff/operation_trees"
20
26
  autoload :OperationTreeBuilders, "super_diff/operation_tree_builders"
21
27
  autoload :Operations, "super_diff/operations"
22
28
  autoload :RecursionGuard, "super_diff/recursion_guard"
23
29
 
24
- COLORS = {
25
- alpha: :magenta,
26
- beta: :yellow,
27
- border: :blue,
28
- header: :white,
29
- }.freeze
30
-
31
30
  def self.configure
32
31
  yield configuration
32
+ configuration.updated
33
33
  end
34
34
 
35
35
  def self.configuration
36
36
  @_configuration ||= Configuration.new
37
37
  end
38
38
 
39
+ def self.inspect_object(object, as_lines:, **rest)
40
+ SuperDiff::RecursionGuard.guarding_recursion_of(object) do
41
+ inspection_tree = ObjectInspection::InspectionTreeBuilders::Main.call(
42
+ object
43
+ )
44
+
45
+ if as_lines
46
+ inspection_tree.render_to_lines(object, **rest)
47
+ else
48
+ inspection_tree.render_to_string(object)
49
+ end
50
+ end
51
+ end
52
+
39
53
  def self.time_like?(value)
40
54
  # Check for ActiveSupport's #acts_like_time? for their time-like objects
41
55
  # (like ActiveSupport::TimeWithZone).
42
56
  (value.respond_to?(:acts_like_time?) && value.acts_like_time?) ||
43
57
  value.is_a?(Time)
44
58
  end
59
+
60
+ def self.primitive?(value)
61
+ case value
62
+ when true, false, nil, Symbol, Numeric, Regexp, Class
63
+ true
64
+ else
65
+ false
66
+ end
67
+ end
68
+
69
+ def self.insert_overrides(target_module, mod = nil, &block)
70
+ if mod
71
+ target_module.prepend(mod)
72
+ else
73
+ target_module.prepend(Module.new(&block))
74
+ end
75
+ end
76
+
77
+ def self.insert_singleton_overrides(target_module, mod = nil, &block)
78
+ if mod
79
+ target_module.singleton_class.prepend(mod)
80
+ else
81
+ target_module.singleton_class.prepend(Module.new(&block))
82
+ end
83
+ end
45
84
  end
@@ -2,7 +2,6 @@ require "super_diff/active_support"
2
2
 
3
3
  module SuperDiff
4
4
  module ActiveRecord
5
- autoload :DiffFormatters, "super_diff/active_record/diff_formatters"
6
5
  autoload :Differs, "super_diff/active_record/differs"
7
6
  autoload(
8
7
  :ObjectInspection,
@@ -16,6 +15,10 @@ module SuperDiff
16
15
  :OperationTreeBuilders,
17
16
  "super_diff/active_record/operation_tree_builders",
18
17
  )
18
+ autoload(
19
+ :OperationTreeFlatteners,
20
+ "super_diff/active_record/operation_tree_flatteners",
21
+ )
19
22
 
20
23
  SuperDiff.configure do |config|
21
24
  config.add_extra_differ_classes(
@@ -25,12 +28,9 @@ module SuperDiff
25
28
  OperationTreeBuilders::ActiveRecordModel,
26
29
  OperationTreeBuilders::ActiveRecordRelation,
27
30
  )
28
- config.add_extra_diff_formatter_classes(
29
- DiffFormatters::ActiveRecordRelation,
30
- )
31
- config.add_extra_inspector_classes(
32
- ObjectInspection::Inspectors::ActiveRecordModel,
33
- ObjectInspection::Inspectors::ActiveRecordRelation,
31
+ config.add_extra_inspection_tree_builder_classes(
32
+ ObjectInspection::InspectionTreeBuilders::ActiveRecordModel,
33
+ ObjectInspection::InspectionTreeBuilders::ActiveRecordRelation,
34
34
  )
35
35
  end
36
36
  end
@@ -7,20 +7,10 @@ module SuperDiff
7
7
  actual.is_a?(::ActiveRecord::Relation)
8
8
  end
9
9
 
10
- def call
11
- DiffFormatters::ActiveRecordRelation.call(
12
- operation_tree,
13
- indent_level: indent_level,
14
- )
15
- end
16
-
17
- private
10
+ protected
18
11
 
19
- def operation_tree
20
- OperationTreeBuilders::ActiveRecordRelation.call(
21
- expected: expected,
22
- actual: actual,
23
- )
12
+ def operation_tree_builder_class
13
+ OperationTreeBuilders::ActiveRecordRelation
24
14
  end
25
15
  end
26
16
  end
@@ -2,12 +2,8 @@ module SuperDiff
2
2
  module ActiveRecord
3
3
  module ObjectInspection
4
4
  autoload(
5
- :Inspectors,
6
- "super_diff/active_record/object_inspection/inspectors",
7
- )
8
- autoload(
9
- :MapExtension,
10
- "super_diff/active_record/object_inspection/map_extension",
5
+ :InspectionTreeBuilders,
6
+ "super_diff/active_record/object_inspection/inspection_tree_builders",
11
7
  )
12
8
  end
13
9
  end
@@ -0,0 +1,16 @@
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,44 +1,43 @@
1
1
  module SuperDiff
2
2
  module ActiveRecord
3
3
  module ObjectInspection
4
- module Inspectors
5
- class ActiveRecordModel < SuperDiff::ObjectInspection::Inspectors::Base
4
+ module InspectionTreeBuilders
5
+ class ActiveRecordModel < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
6
6
  def self.applies_to?(value)
7
7
  value.is_a?(::ActiveRecord::Base)
8
8
  end
9
9
 
10
- protected
11
-
12
- def inspection_tree
10
+ def call
13
11
  SuperDiff::ObjectInspection::InspectionTree.new do
14
- add_text do |object|
15
- "#<#{object.class} "
16
- end
12
+ as_lines_when_rendering_to_lines(collection_bookend: :open) do
13
+ add_text do |object|
14
+ "#<#{object.class} "
15
+ end
17
16
 
18
- when_multiline do
19
- add_text "{"
17
+ when_rendering_to_lines do
18
+ add_text "{"
19
+ end
20
20
  end
21
21
 
22
22
  nested do |object|
23
- add_break
24
-
25
23
  insert_separated_list(
26
24
  ["id"] + (object.attributes.keys.sort - ["id"]),
27
- separator: ",",
28
25
  ) do |name|
29
- add_text name
30
- add_text ": "
26
+ as_prefix_when_rendering_to_lines do
27
+ add_text "#{name}: "
28
+ end
29
+
31
30
  add_inspection_of object.read_attribute(name)
32
31
  end
33
32
  end
34
33
 
35
- add_break
34
+ as_lines_when_rendering_to_lines(collection_bookend: :close) do
35
+ when_rendering_to_lines do
36
+ add_text "}"
37
+ end
36
38
 
37
- when_multiline do
38
- add_text "}"
39
+ add_text ">"
39
40
  end
40
-
41
- add_text ">"
42
41
  end
43
42
  end
44
43
  end
@@ -1,24 +1,25 @@
1
1
  module SuperDiff
2
2
  module ActiveRecord
3
3
  module ObjectInspection
4
- module Inspectors
5
- class ActiveRecordRelation < SuperDiff::ObjectInspection::Inspectors::Base
4
+ module InspectionTreeBuilders
5
+ class ActiveRecordRelation < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
6
6
  def self.applies_to?(value)
7
7
  value.is_a?(::ActiveRecord::Relation)
8
8
  end
9
9
 
10
- protected
11
-
12
- def inspection_tree
10
+ def call
13
11
  SuperDiff::ObjectInspection::InspectionTree.new do
14
- add_text "#<ActiveRecord::Relation ["
12
+ as_lines_when_rendering_to_lines(collection_bookend: :open) do
13
+ add_text "#<ActiveRecord::Relation ["
14
+ end
15
15
 
16
16
  nested do |array|
17
17
  insert_array_inspection_of(array)
18
18
  end
19
19
 
20
- add_break
21
- add_text "]>"
20
+ as_lines_when_rendering_to_lines(collection_bookend: :close) do
21
+ add_text "]>"
22
+ end
22
23
  end
23
24
  end
24
25
  end
@@ -0,0 +1,10 @@
1
+ module SuperDiff
2
+ module ActiveRecord
3
+ module OperationTreeFlatteners
4
+ autoload(
5
+ :ActiveRecordRelation,
6
+ "super_diff/active_record/operation_tree_flatteners/active_record_relation",
7
+ )
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ module SuperDiff
2
+ module ActiveRecord
3
+ module OperationTreeFlatteners
4
+ class ActiveRecordRelation < SuperDiff::OperationTreeFlatteners::Collection
5
+ protected
6
+
7
+ def open_token
8
+ "#<ActiveRecord::Relation ["
9
+ end
10
+
11
+ def close_token
12
+ "]>"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -2,13 +2,14 @@ module SuperDiff
2
2
  module ActiveRecord
3
3
  module OperationTrees
4
4
  class ActiveRecordRelation < SuperDiff::OperationTrees::Array
5
- def to_diff(indent_level:, collection_prefix:, add_comma:)
6
- DiffFormatters::ActiveRecordRelation.call(
7
- self,
8
- indent_level: indent_level,
9
- collection_prefix: collection_prefix,
10
- add_comma: add_comma,
11
- )
5
+ def self.applies_to?(value)
6
+ value.is_a?(ActiveRecord::Relation)
7
+ end
8
+
9
+ protected
10
+
11
+ def operation_tree_flattener_class
12
+ OperationTreeFlatteners::ActiveRecordRelation
12
13
  end
13
14
  end
14
15
  end