super_diff 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -1
  3. data/lib/super_diff.rb +27 -6
  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 +81 -8
  24. data/lib/super_diff/csi.rb +1 -2
  25. data/lib/super_diff/csi/four_bit_color.rb +0 -2
  26. data/lib/super_diff/differs/array.rb +1 -1
  27. data/lib/super_diff/differs/base.rb +3 -21
  28. data/lib/super_diff/differs/custom_object.rb +1 -1
  29. data/lib/super_diff/differs/default_object.rb +1 -1
  30. data/lib/super_diff/differs/hash.rb +1 -1
  31. data/lib/super_diff/differs/main.rb +1 -7
  32. data/lib/super_diff/differs/multiline_string.rb +1 -1
  33. data/lib/super_diff/differs/time_like.rb +1 -1
  34. data/lib/super_diff/equality_matchers/array.rb +2 -2
  35. data/lib/super_diff/equality_matchers/default.rb +2 -2
  36. data/lib/super_diff/equality_matchers/hash.rb +2 -2
  37. data/lib/super_diff/equality_matchers/multiline_string.rb +2 -2
  38. data/lib/super_diff/equality_matchers/primitive.rb +4 -7
  39. data/lib/super_diff/equality_matchers/singleline_string.rb +2 -2
  40. data/lib/super_diff/helpers.rb +52 -2
  41. data/lib/super_diff/line.rb +83 -0
  42. data/lib/super_diff/object_inspection.rb +12 -1
  43. data/lib/super_diff/object_inspection/inspection_tree.rb +183 -81
  44. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +44 -0
  45. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +38 -0
  46. data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +27 -0
  47. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +37 -0
  48. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +63 -0
  49. data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/defaults.rb +1 -2
  50. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +46 -0
  51. data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/main.rb +5 -10
  52. data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +21 -0
  53. data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/time_like.rb +19 -18
  54. data/lib/super_diff/object_inspection/nodes.rb +33 -32
  55. data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +97 -0
  56. data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +27 -0
  57. data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +27 -0
  58. data/lib/super_diff/object_inspection/nodes/as_single_line.rb +33 -0
  59. data/lib/super_diff/object_inspection/nodes/base.rb +55 -20
  60. data/lib/super_diff/object_inspection/nodes/inspection.rb +47 -7
  61. data/lib/super_diff/object_inspection/nodes/nesting.rb +16 -5
  62. data/lib/super_diff/object_inspection/nodes/only_when.rb +54 -0
  63. data/lib/super_diff/object_inspection/nodes/text.rb +16 -2
  64. data/lib/super_diff/object_inspection/nodes/when_empty.rb +21 -6
  65. data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +20 -5
  66. data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +27 -0
  67. data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +27 -0
  68. data/lib/super_diff/object_inspection/prefix_for_next_node.rb +6 -0
  69. data/lib/super_diff/object_inspection/prelude_for_next_node.rb +6 -0
  70. data/lib/super_diff/operation_tree_builders/array.rb +7 -10
  71. data/lib/super_diff/operation_tree_builders/base.rb +6 -6
  72. data/lib/super_diff/operation_tree_builders/custom_object.rb +5 -2
  73. data/lib/super_diff/operation_tree_builders/default_object.rb +1 -1
  74. data/lib/super_diff/operation_tree_builders/hash.rb +0 -7
  75. data/lib/super_diff/operation_tree_builders/multiline_string.rb +2 -6
  76. data/lib/super_diff/operation_tree_flatteners.rb +20 -0
  77. data/lib/super_diff/operation_tree_flatteners/array.rb +15 -0
  78. data/lib/super_diff/operation_tree_flatteners/base.rb +54 -0
  79. data/lib/super_diff/operation_tree_flatteners/collection.rb +139 -0
  80. data/lib/super_diff/operation_tree_flatteners/custom_object.rb +28 -0
  81. data/lib/super_diff/operation_tree_flatteners/default_object.rb +32 -0
  82. data/lib/super_diff/operation_tree_flatteners/hash.rb +41 -0
  83. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +17 -0
  84. data/lib/super_diff/operation_trees/array.rb +4 -7
  85. data/lib/super_diff/operation_trees/base.rb +39 -16
  86. data/lib/super_diff/operation_trees/custom_object.rb +4 -8
  87. data/lib/super_diff/operation_trees/default_object.rb +28 -13
  88. data/lib/super_diff/operation_trees/hash.rb +4 -7
  89. data/lib/super_diff/operation_trees/main.rb +1 -1
  90. data/lib/super_diff/operation_trees/multiline_string.rb +4 -7
  91. data/lib/super_diff/operations/binary_operation.rb +1 -6
  92. data/lib/super_diff/operations/unary_operation.rb +2 -30
  93. data/lib/super_diff/recursion_guard.rb +3 -3
  94. data/lib/super_diff/rspec.rb +12 -13
  95. data/lib/super_diff/rspec/monkey_patches.rb +2 -2
  96. data/lib/super_diff/rspec/object_inspection.rb +4 -1
  97. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +44 -0
  98. data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/collection_containing_exactly.rb +9 -8
  99. data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/collection_including.rb +9 -8
  100. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +103 -0
  101. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +36 -0
  102. data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/instance_of.rb +3 -5
  103. data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/kind_of.rb +3 -5
  104. data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/object_having_attributes.rb +10 -12
  105. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/primitive.rb +10 -0
  106. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +33 -0
  107. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +0 -3
  108. data/lib/super_diff/tiered_lines.rb +4 -0
  109. data/lib/super_diff/tiered_lines_elider.rb +490 -0
  110. data/lib/super_diff/tiered_lines_formatter.rb +79 -0
  111. data/lib/super_diff/version.rb +1 -1
  112. data/spec/examples.txt +407 -410
  113. data/spec/integration/rails/active_support_spec.rb +19 -0
  114. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +12 -6
  115. data/spec/integration/rspec/eq_matcher_spec.rb +22 -88
  116. data/spec/integration/rspec/have_attributes_matcher_spec.rb +6 -7
  117. data/spec/integration/rspec/match_array_matcher_spec.rb +14 -7
  118. data/spec/integration/rspec/match_matcher_spec.rb +10 -5
  119. data/spec/spec_helper.rb +1 -0
  120. data/spec/support/command_runner.rb +15 -25
  121. data/spec/support/helpers.rb +21 -0
  122. data/spec/support/integration/helpers.rb +2 -0
  123. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +3 -3
  124. data/spec/support/integration/test_programs/base.rb +36 -10
  125. data/spec/support/shared_examples/active_record.rb +3 -2
  126. data/spec/support/shared_examples/active_support.rb +65 -0
  127. data/spec/support/shared_examples/elided_diffs.rb +914 -0
  128. data/spec/support/shared_examples/hash_with_indifferent_access.rb +16 -16
  129. data/spec/support/unit/helpers.rb +15 -0
  130. data/spec/support/unit/matchers/match_output.rb +41 -0
  131. data/spec/unit/active_record/object_inspection_spec.rb +273 -0
  132. data/spec/unit/equality_matchers/main_spec.rb +51 -71
  133. data/spec/unit/helpers_spec.rb +61 -0
  134. data/spec/unit/operation_tree_flatteners/array_spec.rb +604 -0
  135. data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +667 -0
  136. data/spec/unit/operation_tree_flatteners/default_object_spec.rb +687 -0
  137. data/spec/unit/operation_tree_flatteners/hash_spec.rb +632 -0
  138. data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +121 -0
  139. data/spec/unit/rspec/object_inspection_spec.rb +446 -0
  140. data/spec/unit/super_diff_spec.rb +1488 -846
  141. data/spec/unit/tiered_lines_elider_spec.rb +6356 -0
  142. data/spec/unit/tiered_lines_formatter_spec.rb +193 -0
  143. metadata +88 -50
  144. data/lib/super_diff/active_record/diff_formatters.rb +0 -10
  145. data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +0 -23
  146. data/lib/super_diff/active_record/object_inspection/inspectors.rb +0 -16
  147. data/lib/super_diff/active_support/diff_formatters.rb +0 -10
  148. data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +0 -36
  149. data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +0 -28
  150. data/lib/super_diff/diff_formatters.rb +0 -14
  151. data/lib/super_diff/diff_formatters/array.rb +0 -21
  152. data/lib/super_diff/diff_formatters/base.rb +0 -33
  153. data/lib/super_diff/diff_formatters/custom_object.rb +0 -30
  154. data/lib/super_diff/diff_formatters/default_object.rb +0 -46
  155. data/lib/super_diff/diff_formatters/defaults.rb +0 -10
  156. data/lib/super_diff/diff_formatters/hash.rb +0 -34
  157. data/lib/super_diff/diff_formatters/main.rb +0 -41
  158. data/lib/super_diff/object_inspection/inspectors.rb +0 -23
  159. data/lib/super_diff/object_inspection/inspectors/array.rb +0 -32
  160. data/lib/super_diff/object_inspection/inspectors/base.rb +0 -36
  161. data/lib/super_diff/object_inspection/inspectors/custom_object.rb +0 -37
  162. data/lib/super_diff/object_inspection/inspectors/default_object.rb +0 -61
  163. data/lib/super_diff/object_inspection/inspectors/hash.rb +0 -32
  164. data/lib/super_diff/object_inspection/inspectors/primitive.rb +0 -28
  165. data/lib/super_diff/object_inspection/inspectors/string.rb +0 -23
  166. data/lib/super_diff/object_inspection/nodes/break.rb +0 -15
  167. data/lib/super_diff/object_inspection/nodes/when_multiline.rb +0 -22
  168. data/lib/super_diff/object_inspection/nodes/when_singleline.rb +0 -24
  169. data/lib/super_diff/rspec/object_inspection/inspectors.rb +0 -40
  170. data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +0 -36
  171. data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +0 -13
  172. data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +0 -29
  173. data/spec/support/object_id.rb +0 -27
  174. data/spec/support/ruby_versions.rb +0 -11
@@ -0,0 +1,44 @@
1
+ module SuperDiff
2
+ module ObjectInspection
3
+ module InspectionTreeBuilders
4
+ autoload(
5
+ :Base,
6
+ "super_diff/object_inspection/inspection_tree_builders/base",
7
+ )
8
+ autoload(
9
+ :Array,
10
+ "super_diff/object_inspection/inspection_tree_builders/array",
11
+ )
12
+ autoload(
13
+ :CustomObject,
14
+ "super_diff/object_inspection/inspection_tree_builders/custom_object",
15
+ )
16
+ autoload(
17
+ :DefaultObject,
18
+ "super_diff/object_inspection/inspection_tree_builders/default_object",
19
+ )
20
+ autoload(
21
+ :Hash,
22
+ "super_diff/object_inspection/inspection_tree_builders/hash",
23
+ )
24
+ autoload(
25
+ :Main,
26
+ "super_diff/object_inspection/inspection_tree_builders/main",
27
+ )
28
+ autoload(
29
+ :Primitive,
30
+ "super_diff/object_inspection/inspection_tree_builders/primitive",
31
+ )
32
+ autoload(
33
+ :String,
34
+ "super_diff/object_inspection/inspection_tree_builders/string",
35
+ )
36
+ autoload(
37
+ :TimeLike,
38
+ "super_diff/object_inspection/inspection_tree_builders/time_like",
39
+ )
40
+ end
41
+ end
42
+ end
43
+
44
+ require "super_diff/object_inspection/inspection_tree_builders/defaults"
@@ -0,0 +1,38 @@
1
+ module SuperDiff
2
+ module ObjectInspection
3
+ module InspectionTreeBuilders
4
+ class Array < Base
5
+ def self.applies_to?(value)
6
+ value.is_a?(::Array)
7
+ end
8
+
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 "[]"
17
+ end
18
+ end
19
+
20
+ only_when nonempty do
21
+ as_lines_when_rendering_to_lines(collection_bookend: :open) do
22
+ add_text "["
23
+ end
24
+
25
+ nested do |array|
26
+ insert_array_inspection_of(array)
27
+ end
28
+
29
+ as_lines_when_rendering_to_lines(collection_bookend: :close) do
30
+ add_text "]"
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,27 @@
1
+ module SuperDiff
2
+ module ObjectInspection
3
+ module InspectionTreeBuilders
4
+ class Base
5
+ extend AttrExtras.mixin
6
+ extend ImplementationChecks
7
+ include ImplementationChecks
8
+
9
+ def self.applies_to?(_value)
10
+ unimplemented_class_method!
11
+ end
12
+
13
+ method_object :object
14
+
15
+ def call
16
+ unimplemented_instance_method!
17
+ end
18
+
19
+ protected
20
+
21
+ def inspection_tree
22
+ unimplemented_instance_method!
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,37 @@
1
+ module SuperDiff
2
+ module ObjectInspection
3
+ module InspectionTreeBuilders
4
+ class CustomObject < Base
5
+ def self.applies_to?(value)
6
+ value.respond_to?(:attributes_for_super_diff)
7
+ end
8
+
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
15
+
16
+ when_rendering_to_lines do
17
+ add_text "{"
18
+ end
19
+ end
20
+
21
+ nested do |object|
22
+ insert_hash_inspection_of(object.attributes_for_super_diff)
23
+ end
24
+
25
+ as_lines_when_rendering_to_lines(collection_bookend: :close) do
26
+ when_rendering_to_lines do
27
+ add_text "}"
28
+ end
29
+
30
+ add_text ">"
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,63 @@
1
+ module SuperDiff
2
+ module ObjectInspection
3
+ module InspectionTreeBuilders
4
+ class DefaultObject < Base
5
+ def self.applies_to?(_value)
6
+ true
7
+ end
8
+
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|
17
+ "#<#{object.class.name}:" +
18
+ SuperDiff::Helpers.object_address_for(object) +
19
+ ">"
20
+ end
21
+ end
22
+ end
23
+
24
+ only_when nonempty do
25
+ as_lines_when_rendering_to_lines(collection_bookend: :open) do
26
+ add_text do |object|
27
+ "#<#{object.class.name}:" +
28
+ SuperDiff::Helpers.object_address_for(object)
29
+ end
30
+
31
+ when_rendering_to_lines do
32
+ add_text " {"
33
+ end
34
+ end
35
+
36
+ when_rendering_to_string do
37
+ add_text " "
38
+ end
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}="
44
+ end
45
+
46
+ add_inspection_of object.instance_variable_get(name)
47
+ end
48
+ end
49
+
50
+ as_lines_when_rendering_to_lines(collection_bookend: :close) do
51
+ when_rendering_to_lines do
52
+ add_text "}"
53
+ end
54
+
55
+ add_text ">"
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -1,12 +1,11 @@
1
1
  module SuperDiff
2
2
  module ObjectInspection
3
- module Inspectors
3
+ module InspectionTreeBuilders
4
4
  DEFAULTS = [
5
5
  CustomObject,
6
6
  Array,
7
7
  Hash,
8
8
  Primitive,
9
- String,
10
9
  TimeLike,
11
10
  DefaultObject,
12
11
  ].freeze
@@ -0,0 +1,46 @@
1
+ module SuperDiff
2
+ module ObjectInspection
3
+ module InspectionTreeBuilders
4
+ class Hash < Base
5
+ def self.applies_to?(value)
6
+ value.is_a?(::Hash)
7
+ end
8
+
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 "{}"
17
+ end
18
+ end
19
+
20
+ only_when nonempty do
21
+ as_lines_when_rendering_to_lines(collection_bookend: :open) do
22
+ add_text "{"
23
+ end
24
+
25
+ when_rendering_to_string do
26
+ add_text " "
27
+ end
28
+
29
+ nested do |hash|
30
+ insert_hash_inspection_of(hash)
31
+ end
32
+
33
+ when_rendering_to_string do
34
+ add_text " "
35
+ end
36
+
37
+ as_lines_when_rendering_to_lines(collection_bookend: :close) do
38
+ add_text "}"
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,18 +1,14 @@
1
1
  module SuperDiff
2
2
  module ObjectInspection
3
- module Inspectors
3
+ module InspectionTreeBuilders
4
4
  class Main
5
5
  extend AttrExtras.mixin
6
6
 
7
- method_object :object, [:as_single_line!, :indent_level!]
7
+ method_object :object
8
8
 
9
9
  def call
10
10
  if resolved_class
11
- resolved_class.call(
12
- object,
13
- as_single_line: as_single_line?,
14
- indent_level: indent_level,
15
- )
11
+ resolved_class.call(object)
16
12
  else
17
13
  raise NoInspectorAvailableError.create(object)
18
14
  end
@@ -20,14 +16,13 @@ module SuperDiff
20
16
 
21
17
  private
22
18
 
23
- attr_query :as_single_line?
24
-
25
19
  def resolved_class
26
20
  available_classes.find { |klass| klass.applies_to?(object) }
27
21
  end
28
22
 
29
23
  def available_classes
30
- SuperDiff.configuration.extra_inspector_classes + DEFAULTS
24
+ SuperDiff.configuration.extra_inspection_tree_builder_classes +
25
+ DEFAULTS
31
26
  end
32
27
  end
33
28
  end
@@ -0,0 +1,21 @@
1
+ module SuperDiff
2
+ module ObjectInspection
3
+ module InspectionTreeBuilders
4
+ class Primitive < Base
5
+ def self.applies_to?(value)
6
+ SuperDiff.primitive?(value) || value.is_a?(::String)
7
+ end
8
+
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
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,20 +1,24 @@
1
1
  module SuperDiff
2
2
  module ObjectInspection
3
- module Inspectors
3
+ module InspectionTreeBuilders
4
4
  class TimeLike < Base
5
5
  def self.applies_to?(value)
6
6
  SuperDiff.time_like?(value)
7
7
  end
8
8
 
9
- protected
10
-
11
- def inspection_tree
9
+ def call
12
10
  InspectionTree.new do
13
- add_text do |time|
14
- "#<#{time.class} "
11
+ as_lines_when_rendering_to_lines(collection_bookend: :open) do
12
+ add_text do |time|
13
+ "#<#{time.class} "
14
+ end
15
+
16
+ when_rendering_to_lines do
17
+ add_text "{"
18
+ end
15
19
  end
16
20
 
17
- when_singleline do
21
+ when_rendering_to_string do
18
22
  add_text do |time|
19
23
  time.strftime("%Y-%m-%d %H:%M:%S") +
20
24
  (time.subsec == 0 ? "" : "+#{time.subsec.inspect}") +
@@ -23,12 +27,8 @@ module SuperDiff
23
27
  end
24
28
  end
25
29
 
26
- when_multiline do
27
- add_text "{"
28
-
30
+ when_rendering_to_lines do
29
31
  nested do |time|
30
- add_break " "
31
-
32
32
  insert_separated_list(
33
33
  [
34
34
  :year,
@@ -40,21 +40,22 @@ module SuperDiff
40
40
  :subsec,
41
41
  :zone,
42
42
  :utc_offset
43
- ],
44
- separator: ","
43
+ ]
45
44
  ) do |name|
46
45
  add_text name.to_s
47
46
  add_text ": "
48
47
  add_inspection_of time.public_send(name)
49
48
  end
50
49
  end
50
+ end
51
51
 
52
- add_break
52
+ as_lines_when_rendering_to_lines(collection_bookend: :close) do
53
+ when_rendering_to_lines do
54
+ add_text "}"
55
+ end
53
56
 
54
- add_text "}"
57
+ add_text ">"
55
58
  end
56
-
57
- add_text ">"
58
59
  end
59
60
  end
60
61
  end
@@ -1,48 +1,49 @@
1
1
  module SuperDiff
2
2
  module ObjectInspection
3
3
  module Nodes
4
- autoload :Base, "super_diff/object_inspection/nodes/base"
5
- autoload :Break, "super_diff/object_inspection/nodes/break"
6
- autoload :Inspection, "super_diff/object_inspection/nodes/inspection"
7
- autoload :Nesting, "super_diff/object_inspection/nodes/nesting"
8
- autoload :Text, "super_diff/object_inspection/nodes/text"
9
4
  autoload(
10
- :WhenEmpty,
11
- "super_diff/object_inspection/nodes/when_empty",
5
+ :AsLinesWhenRenderingToLines,
6
+ "super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines",
12
7
  )
13
8
  autoload(
14
- :WhenMultiline,
15
- "super_diff/object_inspection/nodes/when_multiline",
9
+ :AsPrefixWhenRenderingToLines,
10
+ "super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines",
16
11
  )
17
12
  autoload(
18
- :WhenNonEmpty,
19
- "super_diff/object_inspection/nodes/when_non_empty",
13
+ :AsPreludeWhenRenderingToLines,
14
+ "super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines",
20
15
  )
21
16
  autoload(
22
- :WhenSingleline,
23
- "super_diff/object_inspection/nodes/when_singleline",
17
+ :AsSingleLine,
18
+ "super_diff/object_inspection/nodes/as_single_line",
19
+ )
20
+ autoload :Base, "super_diff/object_inspection/nodes/base"
21
+ autoload :Inspection, "super_diff/object_inspection/nodes/inspection"
22
+ autoload :Nesting, "super_diff/object_inspection/nodes/nesting"
23
+ autoload :OnlyWhen, "super_diff/object_inspection/nodes/only_when"
24
+ autoload :Text, "super_diff/object_inspection/nodes/text"
25
+ autoload(
26
+ :WhenRenderingToLines,
27
+ "super_diff/object_inspection/nodes/when_rendering_to_lines",
28
+ )
29
+ autoload(
30
+ :WhenRenderingToString,
31
+ "super_diff/object_inspection/nodes/when_rendering_to_string",
24
32
  )
25
-
26
- def self.fetch(type)
27
- registry.fetch(type) do
28
- raise(
29
- KeyError,
30
- "#{type.inspect} is not included in ObjectInspection::Nodes.registry!",
31
- )
32
- end
33
- end
34
33
 
35
34
  def self.registry
36
- @_registry ||= {
37
- break: Break,
38
- inspection: Inspection,
39
- nesting: Nesting,
40
- text: Text,
41
- when_empty: WhenEmpty,
42
- when_multiline: WhenMultiline,
43
- when_non_empty: WhenNonEmpty,
44
- when_singleline: WhenSingleline,
45
- }
35
+ @_registry ||= [
36
+ AsLinesWhenRenderingToLines,
37
+ AsPrefixWhenRenderingToLines,
38
+ AsPreludeWhenRenderingToLines,
39
+ AsSingleLine,
40
+ Inspection,
41
+ Nesting,
42
+ OnlyWhen,
43
+ Text,
44
+ WhenRenderingToLines,
45
+ WhenRenderingToString,
46
+ ]
46
47
  end
47
48
  end
48
49
  end