super_diff 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) 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 +5 -13
  6. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +1 -3
  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 +3 -9
  18. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +1 -1
  19. data/lib/super_diff/active_support/object_inspection.rb +1 -1
  20. data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +5 -6
  21. data/lib/super_diff/active_support/operation_tree_builders.rb +1 -1
  22. data/lib/super_diff/active_support/operation_tree_flatteners.rb +1 -1
  23. data/lib/super_diff/active_support/operation_trees.rb +1 -1
  24. data/lib/super_diff/active_support.rb +6 -11
  25. data/lib/super_diff/colorized_document_extensions.rb +2 -4
  26. data/lib/super_diff/configuration.rb +14 -8
  27. data/lib/super_diff/csi/color.rb +4 -4
  28. data/lib/super_diff/csi/colorized_document.rb +12 -16
  29. data/lib/super_diff/csi/document.rb +8 -19
  30. data/lib/super_diff/csi/eight_bit_color.rb +19 -19
  31. data/lib/super_diff/csi/four_bit_color.rb +82 -31
  32. data/lib/super_diff/csi/twenty_four_bit_color.rb +12 -11
  33. data/lib/super_diff/csi/uncolorized_document.rb +2 -6
  34. data/lib/super_diff/csi.rb +10 -14
  35. data/lib/super_diff/diff_formatters/collection.rb +35 -41
  36. data/lib/super_diff/differs/default_object.rb +1 -1
  37. data/lib/super_diff/differs/defaults.rb +1 -1
  38. data/lib/super_diff/differs/main.rb +2 -13
  39. data/lib/super_diff/equality_matchers/array.rb +10 -12
  40. data/lib/super_diff/equality_matchers/base.rb +1 -1
  41. data/lib/super_diff/equality_matchers/default.rb +2 -4
  42. data/lib/super_diff/equality_matchers/defaults.rb +1 -1
  43. data/lib/super_diff/equality_matchers/hash.rb +10 -12
  44. data/lib/super_diff/equality_matchers/multiline_string.rb +11 -13
  45. data/lib/super_diff/equality_matchers/primitive.rb +10 -12
  46. data/lib/super_diff/equality_matchers/singleline_string.rb +10 -12
  47. data/lib/super_diff/equality_matchers.rb +1 -1
  48. data/lib/super_diff/errors.rb +3 -3
  49. data/lib/super_diff/gem_version.rb +3 -3
  50. data/lib/super_diff/helpers.rb +10 -10
  51. data/lib/super_diff/implementation_checks.rb +2 -2
  52. data/lib/super_diff/line.rb +3 -3
  53. data/lib/super_diff/object_inspection/inspection_tree.rb +46 -60
  54. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +2 -6
  55. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +3 -9
  56. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +5 -14
  57. data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +1 -1
  58. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +4 -12
  59. data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +6 -23
  60. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +9 -9
  61. data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +8 -20
  62. data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +1 -5
  63. data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +1 -5
  64. data/lib/super_diff/object_inspection/nodes/as_single_line.rb +3 -7
  65. data/lib/super_diff/object_inspection/nodes/base.rb +9 -14
  66. data/lib/super_diff/object_inspection/nodes/inspection.rb +26 -34
  67. data/lib/super_diff/object_inspection/nodes/nesting.rb +1 -1
  68. data/lib/super_diff/object_inspection/nodes/only_when.rb +2 -6
  69. data/lib/super_diff/object_inspection/nodes/text.rb +1 -5
  70. data/lib/super_diff/object_inspection/nodes/when_empty.rb +2 -6
  71. data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +2 -6
  72. data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +1 -1
  73. data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +1 -5
  74. data/lib/super_diff/object_inspection/nodes.rb +7 -7
  75. data/lib/super_diff/object_inspection.rb +3 -3
  76. data/lib/super_diff/operation_tree_builders/array.rb +12 -11
  77. data/lib/super_diff/operation_tree_builders/base.rb +17 -15
  78. data/lib/super_diff/operation_tree_builders/custom_object.rb +8 -6
  79. data/lib/super_diff/operation_tree_builders/default_object.rb +29 -21
  80. data/lib/super_diff/operation_tree_builders/hash.rb +23 -24
  81. data/lib/super_diff/operation_tree_builders/main.rb +4 -11
  82. data/lib/super_diff/operation_tree_builders/multiline_string.rb +3 -3
  83. data/lib/super_diff/operation_tree_builders/time_like.rb +1 -11
  84. data/lib/super_diff/operation_tree_builders.rb +1 -1
  85. data/lib/super_diff/operation_tree_flatteners/base.rb +1 -5
  86. data/lib/super_diff/operation_tree_flatteners/collection.rb +13 -16
  87. data/lib/super_diff/operation_tree_flatteners/default_object.rb +1 -2
  88. data/lib/super_diff/operation_tree_flatteners/hash.rb +2 -10
  89. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +2 -1
  90. data/lib/super_diff/operation_tree_flatteners.rb +3 -3
  91. data/lib/super_diff/operation_trees/base.rb +3 -5
  92. data/lib/super_diff/operation_trees/default_object.rb +1 -3
  93. data/lib/super_diff/operations/binary_operation.rb +2 -2
  94. data/lib/super_diff/operations/unary_operation.rb +1 -1
  95. data/lib/super_diff/rails.rb +2 -1
  96. data/lib/super_diff/recursion_guard.rb +5 -4
  97. data/lib/super_diff/rspec/augmented_matcher.rb +4 -5
  98. data/lib/super_diff/rspec/differ.rb +6 -13
  99. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -2
  100. data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
  101. data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
  102. data/lib/super_diff/rspec/differs.rb +3 -3
  103. data/lib/super_diff/rspec/matcher_text_builders/base.rb +13 -15
  104. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +5 -7
  105. data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +3 -5
  106. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +1 -5
  107. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +2 -6
  108. data/lib/super_diff/rspec/matcher_text_builders.rb +5 -8
  109. data/lib/super_diff/rspec/matcher_text_template.rb +13 -16
  110. data/lib/super_diff/rspec/monkey_patches.rb +122 -116
  111. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +8 -6
  112. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +11 -16
  113. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +2 -1
  114. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +8 -6
  115. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +8 -6
  116. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +9 -9
  117. data/lib/super_diff/rspec/object_inspection.rb +1 -1
  118. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +11 -10
  119. data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +7 -6
  120. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +11 -10
  121. data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +22 -17
  122. data/lib/super_diff/rspec/operation_tree_builders.rb +4 -4
  123. data/lib/super_diff/rspec.rb +11 -13
  124. data/lib/super_diff/tiered_lines_elider.rb +87 -115
  125. data/lib/super_diff/tiered_lines_formatter.rb +5 -9
  126. data/lib/super_diff/version.rb +1 -1
  127. data/lib/super_diff.rb +4 -9
  128. data/spec/examples.txt +493 -485
  129. data/spec/integration/rails/active_record_spec.rb +3 -1
  130. data/spec/integration/rails/engines_spec.rb +20 -0
  131. data/spec/integration/rails/hash_with_indifferent_access_spec.rb +3 -1
  132. data/spec/integration/rspec/be_falsey_matcher_spec.rb +40 -35
  133. data/spec/integration/rspec/be_matcher_spec.rb +360 -320
  134. data/spec/integration/rspec/be_nil_matcher_spec.rb +38 -34
  135. data/spec/integration/rspec/be_predicate_matcher_spec.rb +376 -359
  136. data/spec/integration/rspec/be_truthy_matcher_spec.rb +38 -33
  137. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +242 -239
  138. data/spec/integration/rspec/eq_matcher_spec.rb +595 -557
  139. data/spec/integration/rspec/have_attributes_matcher_spec.rb +294 -286
  140. data/spec/integration/rspec/have_predicate_matcher_spec.rb +291 -297
  141. data/spec/integration/rspec/include_matcher_spec.rb +317 -215
  142. data/spec/integration/rspec/match_array_matcher_spec.rb +276 -273
  143. data/spec/integration/rspec/match_matcher_spec.rb +847 -834
  144. data/spec/integration/rspec/raise_error_matcher_spec.rb +468 -453
  145. data/spec/integration/rspec/respond_to_matcher_spec.rb +702 -697
  146. data/spec/integration/rspec/third_party_matcher_spec.rb +142 -138
  147. data/spec/integration/rspec/unhandled_errors_spec.rb +88 -84
  148. data/spec/spec_helper.rb +17 -20
  149. data/spec/support/command_runner.rb +34 -57
  150. data/spec/support/integration/helpers.rb +35 -28
  151. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +28 -23
  152. data/spec/support/integration/test_programs/base.rb +12 -17
  153. data/spec/support/integration/test_programs/plain.rb +6 -0
  154. data/spec/support/integration/test_programs/rspec_active_record.rb +4 -1
  155. data/spec/support/integration/test_programs/rspec_active_support.rb +4 -1
  156. data/spec/support/integration/test_programs/rspec_rails.rb +4 -1
  157. data/spec/support/integration/test_programs/rspec_rails_engine.rb +30 -0
  158. data/spec/support/models/active_record/person.rb +6 -4
  159. data/spec/support/models/active_record/shipping_address.rb +9 -10
  160. data/spec/support/models/customer.rb +2 -4
  161. data/spec/support/models/player.rb +3 -6
  162. data/spec/support/models/shipping_address.rb +4 -13
  163. data/spec/support/shared_examples/active_record.rb +232 -214
  164. data/spec/support/shared_examples/active_support.rb +53 -51
  165. data/spec/support/shared_examples/elided_diffs.rb +405 -381
  166. data/spec/support/shared_examples/hash_with_indifferent_access.rb +424 -388
  167. data/spec/support/shared_examples/key.rb +123 -0
  168. data/spec/support/unit/helpers.rb +1 -3
  169. data/spec/support/unit/matchers/match_output.rb +12 -13
  170. data/spec/unit/active_record/object_inspection_spec.rb +222 -206
  171. data/spec/unit/equality_matchers/main_spec.rb +1049 -984
  172. data/spec/unit/helpers_spec.rb +14 -21
  173. data/spec/unit/operation_tree_flatteners/array_spec.rb +557 -524
  174. data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +619 -601
  175. data/spec/unit/operation_tree_flatteners/default_object_spec.rb +619 -621
  176. data/spec/unit/operation_tree_flatteners/hash_spec.rb +595 -556
  177. data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +102 -92
  178. data/spec/unit/rspec/matchers/be_compared_to_spec.rb +3 -3
  179. data/spec/unit/rspec/matchers/be_predicate_spec.rb +3 -3
  180. data/spec/unit/rspec/matchers/contain_exactly_spec.rb +1 -1
  181. data/spec/unit/rspec/matchers/have_attributes_spec.rb +1 -1
  182. data/spec/unit/rspec/matchers/have_predicate_spec.rb +2 -2
  183. data/spec/unit/rspec/matchers/include_spec.rb +2 -2
  184. data/spec/unit/rspec/matchers/match_array_spec.rb +2 -2
  185. data/spec/unit/rspec/matchers/raise_error_spec.rb +5 -5
  186. data/spec/unit/rspec/matchers/respond_to_spec.rb +23 -16
  187. data/spec/unit/rspec/object_inspection_spec.rb +349 -324
  188. data/spec/unit/super_diff_spec.rb +1542 -1449
  189. data/spec/unit/tiered_lines_elider_spec.rb +3508 -3536
  190. data/spec/unit/tiered_lines_formatter_spec.rb +54 -116
  191. data/super_diff.gemspec +13 -12
  192. metadata +73 -73
  193. 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
+ instance_eval(&block) if block
13
11
  end
14
12
 
15
13
  Nodes.registry.each do |node_class|
@@ -34,12 +32,11 @@ module SuperDiff
34
32
  end
35
33
 
36
34
  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
- |
35
+ nodes
36
+ .each_with_index
37
+ .reduce(
38
+ [TieredLines.new, "", ""]
39
+ ) do |(tiered_lines, prelude, prefix), (node, index)|
43
40
  UpdateTieredLines.call(
44
41
  object: object,
45
42
  type: type,
@@ -49,10 +46,10 @@ module SuperDiff
49
46
  prelude: prelude,
50
47
  prefix: prefix,
51
48
  node: node,
52
- index: index,
49
+ index: index
53
50
  )
54
- end.
55
- first
51
+ end
52
+ .first
56
53
  end
57
54
 
58
55
  def evaluate_block(object, &block)
@@ -74,15 +71,11 @@ module SuperDiff
74
71
  def insert_hash_inspection_of(hash)
75
72
  keys = hash.keys
76
73
 
77
- format_keys_as_kwargs = keys.all? do |key|
78
- key.is_a?(Symbol)
79
- end
74
+ format_keys_as_kwargs = keys.all? { |key| key.is_a?(Symbol) }
80
75
 
81
76
  insert_separated_list(keys) do |key|
82
77
  if format_keys_as_kwargs
83
- as_prefix_when_rendering_to_lines do
84
- add_text "#{key}: "
85
- end
78
+ as_prefix_when_rendering_to_lines { add_text "#{key}: " }
86
79
  else
87
80
  as_prefix_when_rendering_to_lines do
88
81
  add_inspection_of key, as_lines: false
@@ -103,13 +96,9 @@ module SuperDiff
103
96
  def insert_separated_list(enumerable, &block)
104
97
  enumerable.each_with_index do |value, index|
105
98
  as_lines_when_rendering_to_lines(
106
- add_comma: index < enumerable.size - 1,
99
+ add_comma: index < enumerable.size - 1
107
100
  ) do
108
- if index > 0
109
- when_rendering_to_string do
110
- add_text " "
111
- end
112
- end
101
+ when_rendering_to_string { add_text " " } if index > 0
113
102
 
114
103
  evaluate_block(value, &block)
115
104
  end
@@ -139,17 +128,17 @@ module SuperDiff
139
128
  class UpdateTieredLines
140
129
  extend AttrExtras.mixin
141
130
 
142
- method_object [
143
- :object!,
144
- :type!,
145
- :indentation_level!,
146
- :nodes!,
147
- :tiered_lines!,
148
- :prelude!,
149
- :prefix!,
150
- :node!,
151
- :index!
152
- ]
131
+ method_object %i[
132
+ object!
133
+ type!
134
+ indentation_level!
135
+ nodes!
136
+ tiered_lines!
137
+ prelude!
138
+ prefix!
139
+ node!
140
+ index!
141
+ ]
153
142
 
154
143
  def call
155
144
  if rendering.is_a?(Array)
@@ -168,19 +157,13 @@ module SuperDiff
168
157
  private
169
158
 
170
159
  def concat_with_lines
171
- additional_lines = prefix_with(
172
- prefix,
173
- prepend_with(prelude, rendering),
174
- )
160
+ additional_lines =
161
+ prefix_with(prefix, prepend_with(prelude, rendering))
175
162
  [tiered_lines + additional_lines, "", ""]
176
163
  end
177
164
 
178
165
  def prefix_with(prefix, text)
179
- if prefix.empty?
180
- text
181
- else
182
- [text[0].prefixed_with(prefix)] + text[1..-1]
183
- end
166
+ prefix.empty? ? text : [text[0].prefixed_with(prefix)] + text[1..-1]
184
167
  end
185
168
 
186
169
  def prepend_with(prelude, text)
@@ -196,9 +179,9 @@ module SuperDiff
196
179
  end
197
180
 
198
181
  def add_to_last_line
199
- new_lines = tiered_lines[0..-2] + [
200
- tiered_lines[-1].with_value_appended(rendering),
201
- ]
182
+ new_lines =
183
+ tiered_lines[0..-2] +
184
+ [tiered_lines[-1].with_value_appended(rendering)]
202
185
  [new_lines, prelude, prefix]
203
186
  end
204
187
 
@@ -207,13 +190,15 @@ module SuperDiff
207
190
  end
208
191
 
209
192
  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
- ]
193
+ new_lines =
194
+ tiered_lines +
195
+ [
196
+ Line.new(
197
+ type: type,
198
+ indentation_level: indentation_level,
199
+ value: rendering
200
+ )
201
+ ]
217
202
  [new_lines, prelude, prefix]
218
203
  end
219
204
 
@@ -221,12 +206,13 @@ module SuperDiff
221
206
  if defined?(@_rendering)
222
207
  @_rendering
223
208
  else
224
- @_rendering = node.render(
225
- object,
226
- preferably_as_lines: true,
227
- type: type,
228
- indentation_level: indentation_level,
229
- )
209
+ @_rendering =
210
+ node.render(
211
+ object,
212
+ preferably_as_lines: true,
213
+ type: type,
214
+ indentation_level: indentation_level
215
+ )
230
216
  end
231
217
  end
232
218
  end
@@ -12,9 +12,7 @@ module SuperDiff
12
12
 
13
13
  InspectionTree.new do
14
14
  only_when empty do
15
- as_lines_when_rendering_to_lines do
16
- add_text "[]"
17
- end
15
+ as_lines_when_rendering_to_lines { add_text "[]" }
18
16
  end
19
17
 
20
18
  only_when nonempty do
@@ -22,9 +20,7 @@ module SuperDiff
22
20
  add_text "["
23
21
  end
24
22
 
25
- nested do |array|
26
- insert_array_inspection_of(array)
27
- end
23
+ nested { |array| insert_array_inspection_of(array) }
28
24
 
29
25
  as_lines_when_rendering_to_lines(collection_bookend: :close) do
30
26
  add_text "]"
@@ -9,13 +9,9 @@ module SuperDiff
9
9
  def call
10
10
  InspectionTree.new do
11
11
  as_lines_when_rendering_to_lines(collection_bookend: :open) do
12
- add_text do |object|
13
- "#<#{object.class} "
14
- end
12
+ add_text { |object| "#<#{object.class} " }
15
13
 
16
- when_rendering_to_lines do
17
- add_text "{"
18
- end
14
+ when_rendering_to_lines { add_text "{" }
19
15
  end
20
16
 
21
17
  nested do |object|
@@ -23,9 +19,7 @@ module SuperDiff
23
19
  end
24
20
 
25
21
  as_lines_when_rendering_to_lines(collection_bookend: :close) do
26
- when_rendering_to_lines do
27
- add_text "}"
28
- end
22
+ when_rendering_to_lines { add_text "}" }
29
23
 
30
24
  add_text ">"
31
25
  end
@@ -15,8 +15,7 @@ module SuperDiff
15
15
  as_lines_when_rendering_to_lines do
16
16
  add_text do |object|
17
17
  "#<#{object.class.name}:" +
18
- SuperDiff::Helpers.object_address_for(object) +
19
- ">"
18
+ SuperDiff::Helpers.object_address_for(object) + ">"
20
19
  end
21
20
  end
22
21
  end
@@ -28,29 +27,21 @@ module SuperDiff
28
27
  SuperDiff::Helpers.object_address_for(object)
29
28
  end
30
29
 
31
- when_rendering_to_lines do
32
- add_text " {"
33
- end
30
+ when_rendering_to_lines { add_text " {" }
34
31
  end
35
32
 
36
- when_rendering_to_string do
37
- add_text " "
38
- end
33
+ when_rendering_to_string { add_text " " }
39
34
 
40
35
  nested do |object|
41
36
  insert_separated_list(object.instance_variables.sort) do |name|
42
- as_prefix_when_rendering_to_lines do
43
- add_text "#{name}="
44
- end
37
+ as_prefix_when_rendering_to_lines { add_text "#{name}=" }
45
38
 
46
39
  add_inspection_of object.instance_variable_get(name)
47
40
  end
48
41
  end
49
42
 
50
43
  as_lines_when_rendering_to_lines(collection_bookend: :close) do
51
- when_rendering_to_lines do
52
- add_text "}"
53
- end
44
+ when_rendering_to_lines { add_text "}" }
54
45
 
55
46
  add_text ">"
56
47
  end
@@ -7,7 +7,7 @@ module SuperDiff
7
7
  Hash,
8
8
  Primitive,
9
9
  TimeLike,
10
- DefaultObject,
10
+ DefaultObject
11
11
  ].freeze
12
12
  end
13
13
  end
@@ -12,9 +12,7 @@ module SuperDiff
12
12
 
13
13
  InspectionTree.new do
14
14
  only_when empty do
15
- as_lines_when_rendering_to_lines do
16
- add_text "{}"
17
- end
15
+ as_lines_when_rendering_to_lines { add_text "{}" }
18
16
  end
19
17
 
20
18
  only_when nonempty do
@@ -22,17 +20,11 @@ module SuperDiff
22
20
  add_text "{"
23
21
  end
24
22
 
25
- when_rendering_to_string do
26
- add_text " "
27
- end
23
+ when_rendering_to_string { add_text " " }
28
24
 
29
- nested do |hash|
30
- insert_hash_inspection_of(hash)
31
- end
25
+ nested { |hash| insert_hash_inspection_of(hash) }
32
26
 
33
- when_rendering_to_string do
34
- add_text " "
35
- end
27
+ when_rendering_to_string { add_text " " }
36
28
 
37
29
  as_lines_when_rendering_to_lines(collection_bookend: :close) do
38
30
  add_text "}"
@@ -9,38 +9,23 @@ module SuperDiff
9
9
  def call
10
10
  InspectionTree.new do
11
11
  as_lines_when_rendering_to_lines(collection_bookend: :open) do
12
- add_text do |time|
13
- "#<#{time.class} "
14
- end
12
+ add_text { |time| "#<#{time.class} " }
15
13
 
16
- when_rendering_to_lines do
17
- add_text "{"
18
- end
14
+ when_rendering_to_lines { add_text "{" }
19
15
  end
20
16
 
21
17
  when_rendering_to_string do
22
18
  add_text do |time|
23
19
  time.strftime("%Y-%m-%d %H:%M:%S") +
24
- (time.subsec == 0 ? "" : "+#{time.subsec.inspect}") +
25
- " " + time.strftime("%:z") +
26
- (time.zone ? " (#{time.zone})" : "")
20
+ (time.subsec == 0 ? "" : "+#{time.subsec.inspect}") + " " +
21
+ time.strftime("%:z") + (time.zone ? " (#{time.zone})" : "")
27
22
  end
28
23
  end
29
24
 
30
25
  when_rendering_to_lines do
31
26
  nested do |time|
32
27
  insert_separated_list(
33
- [
34
- :year,
35
- :month,
36
- :day,
37
- :hour,
38
- :min,
39
- :sec,
40
- :subsec,
41
- :zone,
42
- :utc_offset
43
- ]
28
+ %i[year month day hour min sec subsec zone utc_offset]
44
29
  ) do |name|
45
30
  add_text name.to_s
46
31
  add_text ": "
@@ -50,9 +35,7 @@ module SuperDiff
50
35
  end
51
36
 
52
37
  as_lines_when_rendering_to_lines(collection_bookend: :close) do
53
- when_rendering_to_lines do
54
- add_text "}"
55
- end
38
+ when_rendering_to_lines { add_text "}" }
56
39
 
57
40
  add_text ">"
58
41
  end
@@ -3,39 +3,39 @@ module SuperDiff
3
3
  module InspectionTreeBuilders
4
4
  autoload(
5
5
  :Base,
6
- "super_diff/object_inspection/inspection_tree_builders/base",
6
+ "super_diff/object_inspection/inspection_tree_builders/base"
7
7
  )
8
8
  autoload(
9
9
  :Array,
10
- "super_diff/object_inspection/inspection_tree_builders/array",
10
+ "super_diff/object_inspection/inspection_tree_builders/array"
11
11
  )
12
12
  autoload(
13
13
  :CustomObject,
14
- "super_diff/object_inspection/inspection_tree_builders/custom_object",
14
+ "super_diff/object_inspection/inspection_tree_builders/custom_object"
15
15
  )
16
16
  autoload(
17
17
  :DefaultObject,
18
- "super_diff/object_inspection/inspection_tree_builders/default_object",
18
+ "super_diff/object_inspection/inspection_tree_builders/default_object"
19
19
  )
20
20
  autoload(
21
21
  :Hash,
22
- "super_diff/object_inspection/inspection_tree_builders/hash",
22
+ "super_diff/object_inspection/inspection_tree_builders/hash"
23
23
  )
24
24
  autoload(
25
25
  :Main,
26
- "super_diff/object_inspection/inspection_tree_builders/main",
26
+ "super_diff/object_inspection/inspection_tree_builders/main"
27
27
  )
28
28
  autoload(
29
29
  :Primitive,
30
- "super_diff/object_inspection/inspection_tree_builders/primitive",
30
+ "super_diff/object_inspection/inspection_tree_builders/primitive"
31
31
  )
32
32
  autoload(
33
33
  :String,
34
- "super_diff/object_inspection/inspection_tree_builders/string",
34
+ "super_diff/object_inspection/inspection_tree_builders/string"
35
35
  )
36
36
  autoload(
37
37
  :TimeLike,
38
- "super_diff/object_inspection/inspection_tree_builders/time_like",
38
+ "super_diff/object_inspection/inspection_tree_builders/time_like"
39
39
  )
40
40
  end
41
41
  end
@@ -26,17 +26,9 @@ module SuperDiff
26
26
  def render_to_string(object)
27
27
  # TODO: This happens a lot, can we simplify this?
28
28
  string =
29
- if block
30
- render_to_string_in_subtree(object)
31
- else
32
- immediate_value.to_s
33
- end
29
+ (block ? render_to_string_in_subtree(object) : immediate_value.to_s)
34
30
 
35
- if add_comma?
36
- string + ","
37
- else
38
- string
39
- end
31
+ add_comma? ? string + "," : string
40
32
  end
41
33
 
42
34
  def render_to_lines(object, type:, indentation_level:)
@@ -46,23 +38,20 @@ module SuperDiff
46
38
  object,
47
39
  type: type,
48
40
  indentation_level: indentation_level,
49
- disallowed_node_names: [
50
- :line,
51
- :as_lines_when_rendering_to_lines,
52
- ],
41
+ disallowed_node_names: %i[line as_lines_when_rendering_to_lines]
53
42
  )
54
43
  else
55
44
  [
56
45
  SuperDiff::Line.new(
57
46
  type: type,
58
47
  indentation_level: indentation_level,
59
- value: immediate_value.to_s,
60
- ),
48
+ value: immediate_value.to_s
49
+ )
61
50
  ]
62
51
  end
63
52
 
64
53
  with_collection_bookend_added_to_last_line_in(
65
- with_add_comma_added_to_last_line_in(lines),
54
+ with_add_comma_added_to_last_line_in(lines)
66
55
  )
67
56
  end
68
57
 
@@ -76,9 +65,8 @@ module SuperDiff
76
65
 
77
66
  def with_collection_bookend_added_to_last_line_in(lines)
78
67
  if collection_bookend
79
- lines[0..-2] + [
80
- lines[-1].clone_with(collection_bookend: collection_bookend),
81
- ]
68
+ lines[0..-2] +
69
+ [lines[-1].clone_with(collection_bookend: collection_bookend)]
82
70
  else
83
71
  lines
84
72
  end
@@ -11,11 +11,7 @@ module SuperDiff
11
11
  end
12
12
 
13
13
  def render_to_string(object)
14
- if block
15
- render_to_string_in_subtree(object)
16
- else
17
- immediate_value.to_s
18
- end
14
+ block ? render_to_string_in_subtree(object) : immediate_value.to_s
19
15
  end
20
16
 
21
17
  def render_to_lines(object, **)
@@ -11,11 +11,7 @@ module SuperDiff
11
11
  end
12
12
 
13
13
  def render_to_string(object)
14
- if block
15
- render_to_string_in_subtree(object)
16
- else
17
- immediate_value.to_s
18
- end
14
+ block ? render_to_string_in_subtree(object) : immediate_value.to_s
19
15
  end
20
16
 
21
17
  def render_to_lines(object, **)
@@ -11,11 +11,7 @@ module SuperDiff
11
11
  end
12
12
 
13
13
  def render_to_string(object)
14
- if block
15
- render_to_string_in_subtree(object)
16
- else
17
- immediate_value.to_s
18
- end
14
+ block ? render_to_string_in_subtree(object) : immediate_value.to_s
19
15
  end
20
16
 
21
17
  def render_to_lines(object, type:, indentation_level:)
@@ -23,8 +19,8 @@ module SuperDiff
23
19
  SuperDiff::Line.new(
24
20
  type: type,
25
21
  indentation_level: indentation_level,
26
- value: render_to_string(object),
27
- ),
22
+ value: render_to_string(object)
23
+ )
28
24
  ]
29
25
  end
30
26
  end
@@ -16,9 +16,9 @@ module SuperDiff
16
16
  def initialize(tree, *args, **options, &block)
17
17
  if !args.empty? && block
18
18
  raise ArgumentError.new(
19
- "You cannot provide both an immediate value and a lazy value. " +
20
- "Either pass a block or a positional argument.",
21
- )
19
+ "You cannot provide both an immediate value and a lazy value. " +
20
+ "Either pass a block or a positional argument."
21
+ )
22
22
  end
23
23
 
24
24
  @tree = tree
@@ -50,13 +50,13 @@ module SuperDiff
50
50
 
51
51
  # rubocop:disable Lint/UnusedMethodArgument
52
52
  def render_to_string(object)
53
- # rubocop:enable Lint/UnusedMethodArgument
53
+ # rubocop:enable Lint/UnusedMethodArgument
54
54
  unimplemented_instance_method!
55
55
  end
56
56
 
57
57
  # rubocop:disable Lint/UnusedMethodArgument
58
58
  def render_to_lines(object, type:, indentation_level:)
59
- # rubocop:enable Lint/UnusedMethodArgument
59
+ # rubocop:enable Lint/UnusedMethodArgument
60
60
  unimplemented_instance_method!
61
61
  end
62
62
 
@@ -80,11 +80,7 @@ module SuperDiff
80
80
  attr_reader :tree, :immediate_value, :block, :options
81
81
 
82
82
  def pretty_print_variables
83
- if block
84
- [:"@block"]
85
- else
86
- [:"@immediate_value"]
87
- end
83
+ block ? [:"@block"] : [:"@immediate_value"]
88
84
  end
89
85
 
90
86
  def evaluate_block(object)
@@ -104,15 +100,14 @@ module SuperDiff
104
100
  disallowed_node_names: [],
105
101
  **rest
106
102
  )
107
- subtree = InspectionTree.new(
108
- disallowed_node_names: disallowed_node_names,
109
- )
103
+ subtree =
104
+ InspectionTree.new(disallowed_node_names: disallowed_node_names)
110
105
  subtree.evaluate_block(object, &block)
111
106
  subtree.render_to_lines(
112
107
  object,
113
108
  type: type,
114
109
  indentation_level: indentation_level,
115
- **rest,
110
+ **rest
116
111
  )
117
112
  end
118
113
  end
@@ -11,50 +11,42 @@ module SuperDiff
11
11
  end
12
12
 
13
13
  def render_to_string(object)
14
- value =
15
- if block
16
- evaluate_block(object)
17
- else
18
- immediate_value
19
- end
14
+ value = (block ? evaluate_block(object) : immediate_value)
20
15
 
21
- SuperDiff::RecursionGuard.
22
- guarding_recursion_of(value) do |already_seen|
23
- if already_seen
24
- SuperDiff::RecursionGuard::PLACEHOLDER
25
- else
26
- SuperDiff.inspect_object(value, as_lines: false)
27
- end
16
+ SuperDiff::RecursionGuard.guarding_recursion_of(
17
+ value
18
+ ) do |already_seen|
19
+ if already_seen
20
+ SuperDiff::RecursionGuard::PLACEHOLDER
21
+ else
22
+ SuperDiff.inspect_object(value, as_lines: false)
28
23
  end
24
+ end
29
25
  end
30
26
 
31
27
  def render_to_lines(object, type:, indentation_level:)
32
- value =
33
- if block
34
- evaluate_block(object)
35
- else
36
- immediate_value
37
- end
28
+ value = (block ? evaluate_block(object) : immediate_value)
38
29
 
39
- SuperDiff::RecursionGuard.
40
- guarding_recursion_of(value) do |already_seen|
41
- if already_seen
42
- [
43
- SuperDiff::Line.new(
44
- type: type,
45
- indentation_level: indentation_level,
46
- value: SuperDiff::RecursionGuard::PLACEHOLDER,
47
- ),
48
- ]
49
- else
50
- SuperDiff.inspect_object(
51
- value,
52
- as_lines: true,
30
+ SuperDiff::RecursionGuard.guarding_recursion_of(
31
+ value
32
+ ) do |already_seen|
33
+ if already_seen
34
+ [
35
+ SuperDiff::Line.new(
53
36
  type: type,
54
37
  indentation_level: indentation_level,
38
+ value: SuperDiff::RecursionGuard::PLACEHOLDER
55
39
  )
56
- end
40
+ ]
41
+ else
42
+ SuperDiff.inspect_object(
43
+ value,
44
+ as_lines: true,
45
+ type: type,
46
+ indentation_level: indentation_level
47
+ )
57
48
  end
49
+ end
58
50
  end
59
51
  end
60
52
  end