super_diff 0.9.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +65 -26
  3. data/lib/super_diff/active_record/differs/active_record_relation.rb +1 -2
  4. data/lib/super_diff/active_record/differs.rb +1 -1
  5. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +22 -18
  6. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +14 -7
  7. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +2 -2
  8. data/lib/super_diff/active_record/object_inspection.rb +1 -1
  9. data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +1 -2
  10. data/lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb +1 -2
  11. data/lib/super_diff/active_record/operation_tree_builders.rb +2 -2
  12. data/lib/super_diff/active_record/operation_tree_flatteners.rb +1 -1
  13. data/lib/super_diff/active_record/operation_trees.rb +1 -1
  14. data/lib/super_diff/active_record.rb +7 -15
  15. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +5 -6
  16. data/lib/super_diff/active_support/differs.rb +1 -1
  17. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +20 -11
  18. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb +46 -0
  19. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +5 -1
  20. data/lib/super_diff/active_support/object_inspection.rb +1 -1
  21. data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +5 -6
  22. data/lib/super_diff/active_support/operation_tree_builders.rb +1 -1
  23. data/lib/super_diff/active_support/operation_tree_flatteners.rb +1 -1
  24. data/lib/super_diff/active_support/operation_trees.rb +1 -1
  25. data/lib/super_diff/active_support.rb +6 -10
  26. data/lib/super_diff/colorized_document_extensions.rb +2 -4
  27. data/lib/super_diff/configuration.rb +14 -8
  28. data/lib/super_diff/csi/color.rb +4 -4
  29. data/lib/super_diff/csi/colorized_document.rb +12 -16
  30. data/lib/super_diff/csi/document.rb +8 -19
  31. data/lib/super_diff/csi/eight_bit_color.rb +19 -19
  32. data/lib/super_diff/csi/four_bit_color.rb +82 -31
  33. data/lib/super_diff/csi/twenty_four_bit_color.rb +12 -11
  34. data/lib/super_diff/csi/uncolorized_document.rb +2 -6
  35. data/lib/super_diff/csi.rb +10 -14
  36. data/lib/super_diff/diff_formatters/collection.rb +35 -41
  37. data/lib/super_diff/differs/date_like.rb +15 -0
  38. data/lib/super_diff/differs/default_object.rb +1 -1
  39. data/lib/super_diff/differs/defaults.rb +2 -1
  40. data/lib/super_diff/differs/main.rb +2 -13
  41. data/lib/super_diff/differs.rb +1 -0
  42. data/lib/super_diff/equality_matchers/array.rb +10 -12
  43. data/lib/super_diff/equality_matchers/base.rb +1 -1
  44. data/lib/super_diff/equality_matchers/default.rb +2 -4
  45. data/lib/super_diff/equality_matchers/defaults.rb +1 -1
  46. data/lib/super_diff/equality_matchers/hash.rb +10 -12
  47. data/lib/super_diff/equality_matchers/multiline_string.rb +11 -13
  48. data/lib/super_diff/equality_matchers/primitive.rb +10 -12
  49. data/lib/super_diff/equality_matchers/singleline_string.rb +10 -12
  50. data/lib/super_diff/equality_matchers.rb +1 -1
  51. data/lib/super_diff/errors.rb +2 -6
  52. data/lib/super_diff/gem_version.rb +3 -3
  53. data/lib/super_diff/helpers.rb +10 -10
  54. data/lib/super_diff/implementation_checks.rb +2 -2
  55. data/lib/super_diff/line.rb +3 -3
  56. data/lib/super_diff/object_inspection/inspection_tree.rb +64 -73
  57. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +29 -14
  58. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +17 -13
  59. data/lib/super_diff/object_inspection/inspection_tree_builders/date_like.rb +51 -0
  60. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +43 -27
  61. data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +2 -1
  62. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +35 -18
  63. data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +3 -5
  64. data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +30 -36
  65. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +13 -9
  66. data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +11 -22
  67. data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +1 -5
  68. data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +1 -5
  69. data/lib/super_diff/object_inspection/nodes/as_single_line.rb +3 -7
  70. data/lib/super_diff/object_inspection/nodes/base.rb +9 -14
  71. data/lib/super_diff/object_inspection/nodes/inspection.rb +26 -34
  72. data/lib/super_diff/object_inspection/nodes/nesting.rb +1 -1
  73. data/lib/super_diff/object_inspection/nodes/only_when.rb +2 -6
  74. data/lib/super_diff/object_inspection/nodes/text.rb +1 -5
  75. data/lib/super_diff/object_inspection/nodes/when_empty.rb +2 -6
  76. data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +2 -6
  77. data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +1 -1
  78. data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +1 -5
  79. data/lib/super_diff/object_inspection/nodes.rb +7 -7
  80. data/lib/super_diff/object_inspection.rb +3 -3
  81. data/lib/super_diff/operation_tree_builders/array.rb +12 -11
  82. data/lib/super_diff/operation_tree_builders/base.rb +17 -15
  83. data/lib/super_diff/operation_tree_builders/custom_object.rb +8 -6
  84. data/lib/super_diff/operation_tree_builders/date_like.rb +15 -0
  85. data/lib/super_diff/operation_tree_builders/default_object.rb +29 -21
  86. data/lib/super_diff/operation_tree_builders/defaults.rb +1 -1
  87. data/lib/super_diff/operation_tree_builders/hash.rb +23 -24
  88. data/lib/super_diff/operation_tree_builders/main.rb +4 -11
  89. data/lib/super_diff/operation_tree_builders/multiline_string.rb +3 -3
  90. data/lib/super_diff/operation_tree_builders/time_like.rb +1 -11
  91. data/lib/super_diff/operation_tree_builders.rb +2 -1
  92. data/lib/super_diff/operation_tree_flatteners/base.rb +1 -5
  93. data/lib/super_diff/operation_tree_flatteners/collection.rb +13 -16
  94. data/lib/super_diff/operation_tree_flatteners/default_object.rb +1 -2
  95. data/lib/super_diff/operation_tree_flatteners/hash.rb +2 -10
  96. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +2 -1
  97. data/lib/super_diff/operation_tree_flatteners.rb +3 -3
  98. data/lib/super_diff/operation_trees/base.rb +3 -5
  99. data/lib/super_diff/operation_trees/default_object.rb +1 -3
  100. data/lib/super_diff/operations/binary_operation.rb +2 -2
  101. data/lib/super_diff/operations/unary_operation.rb +1 -1
  102. data/lib/super_diff/rails.rb +2 -1
  103. data/lib/super_diff/recursion_guard.rb +5 -4
  104. data/lib/super_diff/rspec/augmented_matcher.rb +4 -5
  105. data/lib/super_diff/rspec/differ.rb +6 -13
  106. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -2
  107. data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
  108. data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
  109. data/lib/super_diff/rspec/differs.rb +3 -3
  110. data/lib/super_diff/rspec/matcher_text_builders/base.rb +13 -15
  111. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +5 -7
  112. data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +3 -5
  113. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +2 -10
  114. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +2 -6
  115. data/lib/super_diff/rspec/matcher_text_builders.rb +5 -8
  116. data/lib/super_diff/rspec/matcher_text_template.rb +13 -16
  117. data/lib/super_diff/rspec/monkey_patches.rb +180 -123
  118. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb +14 -7
  119. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +21 -13
  120. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +35 -36
  121. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher.rb +19 -0
  122. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +21 -15
  123. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +11 -10
  124. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +11 -10
  125. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +14 -7
  126. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +10 -11
  127. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +13 -9
  128. data/lib/super_diff/rspec/object_inspection.rb +1 -1
  129. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +11 -10
  130. data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +7 -6
  131. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +11 -10
  132. data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +22 -17
  133. data/lib/super_diff/rspec/operation_tree_builders.rb +4 -4
  134. data/lib/super_diff/rspec.rb +17 -18
  135. data/lib/super_diff/tiered_lines_elider.rb +87 -115
  136. data/lib/super_diff/tiered_lines_formatter.rb +5 -9
  137. data/lib/super_diff/version.rb +1 -1
  138. data/lib/super_diff.rb +13 -9
  139. data/spec/examples.txt +541 -483
  140. data/spec/integration/rails/active_record_spec.rb +3 -1
  141. data/spec/integration/rails/engines_spec.rb +25 -0
  142. data/spec/integration/rails/hash_with_indifferent_access_spec.rb +3 -1
  143. data/spec/integration/rspec/be_falsey_matcher_spec.rb +40 -35
  144. data/spec/integration/rspec/be_matcher_spec.rb +360 -320
  145. data/spec/integration/rspec/be_nil_matcher_spec.rb +38 -34
  146. data/spec/integration/rspec/be_predicate_matcher_spec.rb +376 -359
  147. data/spec/integration/rspec/be_truthy_matcher_spec.rb +38 -33
  148. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +257 -254
  149. data/spec/integration/rspec/eq_matcher_spec.rb +695 -585
  150. data/spec/integration/rspec/generic_describable_matchers_spec.rb +177 -0
  151. data/spec/integration/rspec/have_attributes_matcher_spec.rb +312 -304
  152. data/spec/integration/rspec/have_predicate_matcher_spec.rb +291 -297
  153. data/spec/integration/rspec/include_matcher_spec.rb +327 -225
  154. data/spec/integration/rspec/magic_metadata_spec.rb +51 -0
  155. data/spec/integration/rspec/match_array_matcher_spec.rb +294 -291
  156. data/spec/integration/rspec/match_matcher_spec.rb +916 -903
  157. data/spec/integration/rspec/raise_error_matcher_spec.rb +1208 -449
  158. data/spec/integration/rspec/respond_to_matcher_spec.rb +702 -697
  159. data/spec/integration/rspec/third_party_matcher_spec.rb +142 -138
  160. data/spec/integration/rspec/unhandled_errors_spec.rb +88 -84
  161. data/spec/internal/log/test.log +0 -0
  162. data/spec/spec_helper.rb +20 -20
  163. data/spec/support/command_runner.rb +34 -57
  164. data/spec/support/integration/helpers.rb +44 -32
  165. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +28 -23
  166. data/spec/support/integration/matchers.rb +34 -0
  167. data/spec/support/integration/test_programs/base.rb +17 -22
  168. data/spec/support/integration/test_programs/plain.rb +6 -0
  169. data/spec/support/integration/test_programs/rspec_active_record.rb +4 -1
  170. data/spec/support/integration/test_programs/rspec_active_support.rb +4 -1
  171. data/spec/support/integration/test_programs/rspec_rails.rb +4 -1
  172. data/spec/support/integration/test_programs/rspec_rails_engine.rb +20 -0
  173. data/spec/support/models/active_record/person.rb +6 -4
  174. data/spec/support/models/active_record/shipping_address.rb +9 -10
  175. data/spec/support/models/customer.rb +2 -4
  176. data/spec/support/models/player.rb +3 -6
  177. data/spec/support/models/shipping_address.rb +4 -13
  178. data/spec/support/shared_examples/active_record.rb +258 -240
  179. data/spec/support/shared_examples/active_support.rb +174 -51
  180. data/spec/support/shared_examples/elided_diffs.rb +447 -423
  181. data/spec/support/shared_examples/hash_with_indifferent_access.rb +500 -464
  182. data/spec/support/shared_examples/key.rb +123 -0
  183. data/spec/support/unit/helpers.rb +1 -3
  184. data/spec/support/unit/matchers/match_output.rb +12 -13
  185. data/spec/unit/active_record/object_inspection_spec.rb +222 -206
  186. data/spec/unit/active_support/object_inspection_spec.rb +170 -0
  187. data/spec/unit/equality_matchers/main_spec.rb +1049 -984
  188. data/spec/unit/helpers_spec.rb +14 -21
  189. data/spec/unit/operation_tree_flatteners/array_spec.rb +557 -524
  190. data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +619 -601
  191. data/spec/unit/operation_tree_flatteners/default_object_spec.rb +619 -621
  192. data/spec/unit/operation_tree_flatteners/hash_spec.rb +595 -556
  193. data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +102 -92
  194. data/spec/unit/rspec/matchers/be_compared_to_spec.rb +3 -3
  195. data/spec/unit/rspec/matchers/be_predicate_spec.rb +3 -3
  196. data/spec/unit/rspec/matchers/contain_exactly_spec.rb +1 -1
  197. data/spec/unit/rspec/matchers/have_attributes_spec.rb +1 -1
  198. data/spec/unit/rspec/matchers/have_predicate_spec.rb +2 -2
  199. data/spec/unit/rspec/matchers/include_spec.rb +2 -2
  200. data/spec/unit/rspec/matchers/match_array_spec.rb +2 -2
  201. data/spec/unit/rspec/matchers/raise_error_spec.rb +43 -11
  202. data/spec/unit/rspec/matchers/respond_to_spec.rb +23 -16
  203. data/spec/unit/rspec/object_inspection/rspec_matcher_spec.rb +91 -0
  204. data/spec/unit/rspec/object_inspection_spec.rb +351 -326
  205. data/spec/unit/super_diff_spec.rb +1594 -1437
  206. data/spec/unit/tiered_lines_elider_spec.rb +3508 -3536
  207. data/spec/unit/tiered_lines_formatter_spec.rb +54 -116
  208. data/super_diff.gemspec +13 -12
  209. metadata +88 -75
  210. data/lib/super_diff/errors/no_diff_formatter_available_error.rb +0 -21
  211. data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +0 -22
  212. data/spec/tmp/warnings_logger/all_warnings.txt +0 -2
@@ -7,9 +7,7 @@ module SuperDiff
7
7
  @disallowed_node_names = disallowed_node_names
8
8
  @nodes = []
9
9
 
10
- if block
11
- instance_eval(&block)
12
- end
10
+ evaluate_block(&block) if block
13
11
  end
14
12
 
15
13
  Nodes.registry.each do |node_class|
@@ -28,18 +26,16 @@ module SuperDiff
28
26
 
29
27
  def render_to_string(object)
30
28
  nodes.reduce("") do |string, node|
31
- result = node.render_to_string(object)
32
- string + result
29
+ string + node.render_to_string(object)
33
30
  end
34
31
  end
35
32
 
36
33
  def render_to_lines(object, type:, indentation_level:)
37
- nodes.
38
- each_with_index.
39
- reduce([TieredLines.new, "", ""]) do |
40
- (tiered_lines, prelude, prefix),
41
- (node, index)
42
- |
34
+ nodes
35
+ .each_with_index
36
+ .reduce(
37
+ [TieredLines.new, "", ""]
38
+ ) do |(tiered_lines, prelude, prefix), (node, index)|
43
39
  UpdateTieredLines.call(
44
40
  object: object,
45
41
  type: type,
@@ -49,53 +45,51 @@ module SuperDiff
49
45
  prelude: prelude,
50
46
  prefix: prefix,
51
47
  node: node,
52
- index: index,
48
+ index: index
53
49
  )
54
- end.
55
- first
50
+ end
51
+ .first
56
52
  end
57
53
 
58
- def evaluate_block(object, &block)
59
- instance_exec(object, &block)
54
+ def evaluate_block(*args, &block)
55
+ block.call(self, *args)
60
56
  end
61
57
 
62
58
  def insert_array_inspection_of(array)
63
- insert_separated_list(array) do |value|
59
+ insert_separated_list(array) do |t, value|
64
60
  # Have to do these shenanigans so that if value is a hash, Ruby
65
61
  # doesn't try to interpret it as keyword args
66
62
  if SuperDiff::Helpers.ruby_version_matches?(">= 2.7.1")
67
- add_inspection_of(value, **{})
63
+ t.add_inspection_of(value, **{})
68
64
  else
69
- add_inspection_of(*[value, {}])
65
+ t.add_inspection_of(*[value, {}])
70
66
  end
71
67
  end
72
68
  end
73
69
 
74
70
  def insert_hash_inspection_of(hash)
75
71
  keys = hash.keys
72
+ format_keys_as_kwargs = keys.all? { |key| key.is_a?(Symbol) }
76
73
 
77
- format_keys_as_kwargs = keys.all? do |key|
78
- key.is_a?(Symbol)
79
- end
80
-
81
- insert_separated_list(keys) do |key|
74
+ insert_separated_list(keys) do |t1, key|
82
75
  if format_keys_as_kwargs
83
- as_prefix_when_rendering_to_lines do
84
- add_text "#{key}: "
76
+ # stree-ignore
77
+ t1.as_prefix_when_rendering_to_lines do |t2|
78
+ t2.add_text "#{key}: "
85
79
  end
86
80
  else
87
- as_prefix_when_rendering_to_lines do
88
- add_inspection_of key, as_lines: false
89
- add_text " => "
81
+ t1.as_prefix_when_rendering_to_lines do |t2|
82
+ t2.add_inspection_of key, as_lines: false
83
+ t2.add_text " => "
90
84
  end
91
85
  end
92
86
 
93
87
  # Have to do these shenanigans so that if hash[key] is a hash, Ruby
94
88
  # doesn't try to interpret it as keyword args
95
89
  if SuperDiff::Helpers.ruby_version_matches?(">= 2.7.1")
96
- add_inspection_of(hash[key], **{})
90
+ t1.add_inspection_of(hash[key], **{})
97
91
  else
98
- add_inspection_of(*[hash[key], {}])
92
+ t1.add_inspection_of(*[hash[key], {}])
99
93
  end
100
94
  end
101
95
  end
@@ -103,15 +97,15 @@ module SuperDiff
103
97
  def insert_separated_list(enumerable, &block)
104
98
  enumerable.each_with_index do |value, index|
105
99
  as_lines_when_rendering_to_lines(
106
- add_comma: index < enumerable.size - 1,
107
- ) do
100
+ add_comma: index < enumerable.size - 1
101
+ ) do |t1|
108
102
  if index > 0
109
- when_rendering_to_string do
110
- add_text " "
103
+ # stree-ignore
104
+ t1.when_rendering_to_string do |t2|
105
+ t2.add_text " "
111
106
  end
112
107
  end
113
-
114
- evaluate_block(value, &block)
108
+ t1.evaluate_block(value, &block)
115
109
  end
116
110
  end
117
111
  end
@@ -139,17 +133,17 @@ module SuperDiff
139
133
  class UpdateTieredLines
140
134
  extend AttrExtras.mixin
141
135
 
142
- method_object [
143
- :object!,
144
- :type!,
145
- :indentation_level!,
146
- :nodes!,
147
- :tiered_lines!,
148
- :prelude!,
149
- :prefix!,
150
- :node!,
151
- :index!
152
- ]
136
+ method_object %i[
137
+ object!
138
+ type!
139
+ indentation_level!
140
+ nodes!
141
+ tiered_lines!
142
+ prelude!
143
+ prefix!
144
+ node!
145
+ index!
146
+ ]
153
147
 
154
148
  def call
155
149
  if rendering.is_a?(Array)
@@ -168,19 +162,13 @@ module SuperDiff
168
162
  private
169
163
 
170
164
  def concat_with_lines
171
- additional_lines = prefix_with(
172
- prefix,
173
- prepend_with(prelude, rendering),
174
- )
165
+ additional_lines =
166
+ prefix_with(prefix, prepend_with(prelude, rendering))
175
167
  [tiered_lines + additional_lines, "", ""]
176
168
  end
177
169
 
178
170
  def prefix_with(prefix, text)
179
- if prefix.empty?
180
- text
181
- else
182
- [text[0].prefixed_with(prefix)] + text[1..-1]
183
- end
171
+ prefix.empty? ? text : [text[0].prefixed_with(prefix)] + text[1..-1]
184
172
  end
185
173
 
186
174
  def prepend_with(prelude, text)
@@ -196,9 +184,9 @@ module SuperDiff
196
184
  end
197
185
 
198
186
  def add_to_last_line
199
- new_lines = tiered_lines[0..-2] + [
200
- tiered_lines[-1].with_value_appended(rendering),
201
- ]
187
+ new_lines =
188
+ tiered_lines[0..-2] +
189
+ [tiered_lines[-1].with_value_appended(rendering)]
202
190
  [new_lines, prelude, prefix]
203
191
  end
204
192
 
@@ -207,13 +195,15 @@ module SuperDiff
207
195
  end
208
196
 
209
197
  def add_to_lines
210
- new_lines = tiered_lines + [
211
- Line.new(
212
- type: type,
213
- indentation_level: indentation_level,
214
- value: rendering,
215
- ),
216
- ]
198
+ new_lines =
199
+ tiered_lines +
200
+ [
201
+ Line.new(
202
+ type: type,
203
+ indentation_level: indentation_level,
204
+ value: rendering
205
+ )
206
+ ]
217
207
  [new_lines, prelude, prefix]
218
208
  end
219
209
 
@@ -221,12 +211,13 @@ module SuperDiff
221
211
  if defined?(@_rendering)
222
212
  @_rendering
223
213
  else
224
- @_rendering = node.render(
225
- object,
226
- preferably_as_lines: true,
227
- type: type,
228
- indentation_level: indentation_level,
229
- )
214
+ @_rendering =
215
+ node.render(
216
+ object,
217
+ preferably_as_lines: true,
218
+ type: type,
219
+ indentation_level: indentation_level
220
+ )
230
221
  end
231
222
  end
232
223
  end
@@ -7,31 +7,46 @@ module SuperDiff
7
7
  end
8
8
 
9
9
  def call
10
- empty = -> { object.empty? }
11
- nonempty = -> { !object.empty? }
12
-
13
- InspectionTree.new do
14
- only_when empty do
15
- as_lines_when_rendering_to_lines do
16
- add_text "[]"
10
+ InspectionTree.new do |t1|
11
+ t1.only_when empty do |t2|
12
+ # stree-ignore
13
+ t2.as_lines_when_rendering_to_lines do |t3|
14
+ t3.add_text "[]"
17
15
  end
18
16
  end
19
17
 
20
- only_when nonempty do
21
- as_lines_when_rendering_to_lines(collection_bookend: :open) do
22
- add_text "["
18
+ t1.only_when nonempty do |t2|
19
+ # stree-ignore
20
+ t2.as_lines_when_rendering_to_lines(
21
+ collection_bookend: :open
22
+ ) do |t3|
23
+ t3.add_text "["
23
24
  end
24
25
 
25
- nested do |array|
26
- insert_array_inspection_of(array)
26
+ # stree-ignore
27
+ t2.nested do |t3|
28
+ t3.insert_array_inspection_of(object)
27
29
  end
28
30
 
29
- as_lines_when_rendering_to_lines(collection_bookend: :close) do
30
- add_text "]"
31
+ # stree-ignore
32
+ t2.as_lines_when_rendering_to_lines(
33
+ collection_bookend: :close
34
+ ) do |t3|
35
+ t3.add_text "]"
31
36
  end
32
37
  end
33
38
  end
34
39
  end
40
+
41
+ private
42
+
43
+ def empty
44
+ -> { object.empty? }
45
+ end
46
+
47
+ def nonempty
48
+ -> { !object.empty? }
49
+ end
35
50
  end
36
51
  end
37
52
  end
@@ -7,27 +7,31 @@ module SuperDiff
7
7
  end
8
8
 
9
9
  def call
10
- InspectionTree.new do
11
- as_lines_when_rendering_to_lines(collection_bookend: :open) do
12
- add_text do |object|
13
- "#<#{object.class} "
14
- end
10
+ InspectionTree.new do |t1|
11
+ t1.as_lines_when_rendering_to_lines(
12
+ collection_bookend: :open
13
+ ) do |t2|
14
+ t2.add_text "#<#{object.class} "
15
15
 
16
- when_rendering_to_lines do
17
- add_text "{"
16
+ # stree-ignore
17
+ t2.when_rendering_to_lines do |t3|
18
+ t3.add_text "{"
18
19
  end
19
20
  end
20
21
 
21
- nested do |object|
22
- insert_hash_inspection_of(object.attributes_for_super_diff)
22
+ t1.nested do |t2|
23
+ t2.insert_hash_inspection_of(object.attributes_for_super_diff)
23
24
  end
24
25
 
25
- as_lines_when_rendering_to_lines(collection_bookend: :close) do
26
- when_rendering_to_lines do
27
- add_text "}"
26
+ t1.as_lines_when_rendering_to_lines(
27
+ collection_bookend: :close
28
+ ) do |t2|
29
+ # stree-ignore
30
+ t2.when_rendering_to_lines do |t3|
31
+ t3.add_text "}"
28
32
  end
29
33
 
30
- add_text ">"
34
+ t2.add_text ">"
31
35
  end
32
36
  end
33
37
  end
@@ -0,0 +1,51 @@
1
+ module SuperDiff
2
+ module ObjectInspection
3
+ module InspectionTreeBuilders
4
+ class DateLike < Base
5
+ def self.applies_to?(value)
6
+ SuperDiff.date_like?(value)
7
+ end
8
+
9
+ def call
10
+ InspectionTree.new do |t1|
11
+ t1.as_lines_when_rendering_to_lines(
12
+ collection_bookend: :open
13
+ ) do |t2|
14
+ t2.add_text "#<#{object.class} "
15
+
16
+ # stree-ignore
17
+ t2.when_rendering_to_lines do |t3|
18
+ t3.add_text "{"
19
+ end
20
+ end
21
+
22
+ t1.when_rendering_to_string do |t2|
23
+ t2.add_text object.strftime("%Y-%m-%d")
24
+ end
25
+
26
+ t1.when_rendering_to_lines do |t2|
27
+ t2.nested do |t3|
28
+ t3.insert_separated_list(%i[year month day]) do |t4, name|
29
+ t4.add_text name.to_s
30
+ t4.add_text ": "
31
+ t4.add_inspection_of object.public_send(name)
32
+ end
33
+ end
34
+ end
35
+
36
+ t1.as_lines_when_rendering_to_lines(
37
+ collection_bookend: :close
38
+ ) do |t2|
39
+ # stree-ignore
40
+ t2.when_rendering_to_lines do |t3|
41
+ t3.add_text "}"
42
+ end
43
+
44
+ t2.add_text ">"
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -7,56 +7,72 @@ module SuperDiff
7
7
  end
8
8
 
9
9
  def call
10
- empty = -> { object.instance_variables.empty? }
11
- nonempty = -> { !object.instance_variables.empty? }
12
-
13
- InspectionTree.new do
14
- only_when empty do
15
- as_lines_when_rendering_to_lines do
16
- add_text do |object|
10
+ InspectionTree.new do |t1|
11
+ t1.only_when empty do |t2|
12
+ t2.as_lines_when_rendering_to_lines do |t3|
13
+ t3.add_text(
17
14
  "#<#{object.class.name}:" +
18
- SuperDiff::Helpers.object_address_for(object) +
19
- ">"
20
- end
15
+ SuperDiff::Helpers.object_address_for(object) + ">"
16
+ )
21
17
  end
22
18
  end
23
19
 
24
- only_when nonempty do
25
- as_lines_when_rendering_to_lines(collection_bookend: :open) do
26
- add_text do |object|
20
+ t1.only_when nonempty do |t2|
21
+ t2.as_lines_when_rendering_to_lines(
22
+ collection_bookend: :open
23
+ ) do |t3|
24
+ t3.add_text(
27
25
  "#<#{object.class.name}:" +
28
26
  SuperDiff::Helpers.object_address_for(object)
29
- end
27
+ )
30
28
 
31
- when_rendering_to_lines do
32
- add_text " {"
29
+ # stree-ignore
30
+ t3.when_rendering_to_lines do |t4|
31
+ t4.add_text " {"
33
32
  end
34
33
  end
35
34
 
36
- when_rendering_to_string do
37
- add_text " "
35
+ # stree-ignore
36
+ t2.when_rendering_to_string do |t3|
37
+ t3.add_text " "
38
38
  end
39
39
 
40
- nested do |object|
41
- insert_separated_list(object.instance_variables.sort) do |name|
42
- as_prefix_when_rendering_to_lines do
43
- add_text "#{name}="
40
+ t2.nested do |t3|
41
+ t3.insert_separated_list(
42
+ object.instance_variables.sort
43
+ ) do |t4, name|
44
+ # stree-ignore
45
+ t4.as_prefix_when_rendering_to_lines do |t5|
46
+ t5.add_text "#{name}="
44
47
  end
45
48
 
46
- add_inspection_of object.instance_variable_get(name)
49
+ t4.add_inspection_of object.instance_variable_get(name)
47
50
  end
48
51
  end
49
52
 
50
- as_lines_when_rendering_to_lines(collection_bookend: :close) do
51
- when_rendering_to_lines do
52
- add_text "}"
53
+ t2.as_lines_when_rendering_to_lines(
54
+ collection_bookend: :close
55
+ ) do |t3|
56
+ # stree-ignore
57
+ t3.when_rendering_to_lines do |t4|
58
+ t4.add_text "}"
53
59
  end
54
60
 
55
- add_text ">"
61
+ t3.add_text ">"
56
62
  end
57
63
  end
58
64
  end
59
65
  end
66
+
67
+ private
68
+
69
+ def empty
70
+ -> { object.instance_variables.empty? }
71
+ end
72
+
73
+ def nonempty
74
+ -> { !object.instance_variables.empty? }
75
+ end
60
76
  end
61
77
  end
62
78
  end
@@ -7,7 +7,8 @@ module SuperDiff
7
7
  Hash,
8
8
  Primitive,
9
9
  TimeLike,
10
- DefaultObject,
10
+ DateLike,
11
+ DefaultObject
11
12
  ].freeze
12
13
  end
13
14
  end
@@ -7,39 +7,56 @@ module SuperDiff
7
7
  end
8
8
 
9
9
  def call
10
- empty = -> { object.empty? }
11
- nonempty = -> { !object.empty? }
12
-
13
- InspectionTree.new do
14
- only_when empty do
15
- as_lines_when_rendering_to_lines do
16
- add_text "{}"
10
+ InspectionTree.new do |t1|
11
+ t1.only_when empty do |t2|
12
+ # stree-ignore
13
+ t2.as_lines_when_rendering_to_lines do |t3|
14
+ t3.add_text "{}"
17
15
  end
18
16
  end
19
17
 
20
- only_when nonempty do
21
- as_lines_when_rendering_to_lines(collection_bookend: :open) do
22
- add_text "{"
18
+ t1.only_when nonempty do |t2|
19
+ # stree-ignore
20
+ t2.as_lines_when_rendering_to_lines(
21
+ collection_bookend: :open
22
+ ) do |t3|
23
+ t3.add_text "{"
23
24
  end
24
25
 
25
- when_rendering_to_string do
26
- add_text " "
26
+ # stree-ignore
27
+ t2.when_rendering_to_string do |t3|
28
+ t3.add_text " "
27
29
  end
28
30
 
29
- nested do |hash|
30
- insert_hash_inspection_of(hash)
31
+ # stree-ignore
32
+ t2.nested do |t3|
33
+ t3.insert_hash_inspection_of(object)
31
34
  end
32
35
 
33
- when_rendering_to_string do
34
- add_text " "
36
+ # stree-ignore
37
+ t2.when_rendering_to_string do |t3|
38
+ t3.add_text " "
35
39
  end
36
40
 
37
- as_lines_when_rendering_to_lines(collection_bookend: :close) do
38
- add_text "}"
41
+ # stree-ignore
42
+ t2.as_lines_when_rendering_to_lines(
43
+ collection_bookend: :close
44
+ ) do |t3|
45
+ t3.add_text "}"
39
46
  end
40
47
  end
41
48
  end
42
49
  end
50
+
51
+ private
52
+
53
+ def empty
54
+ -> { object.empty? }
55
+ end
56
+
57
+ def nonempty
58
+ -> { !object.empty? }
59
+ end
43
60
  end
44
61
  end
45
62
  end
@@ -7,11 +7,9 @@ module SuperDiff
7
7
  end
8
8
 
9
9
  def call
10
- InspectionTree.new do
11
- as_lines_when_rendering_to_lines do
12
- # rubocop:disable Style/SymbolProc
13
- add_text { |object| object.inspect }
14
- # rubocop:enable Style/SymbolProc
10
+ InspectionTree.new do |t1|
11
+ t1.as_lines_when_rendering_to_lines do |t2|
12
+ t2.add_text object.inspect
15
13
  end
16
14
  end
17
15
  end