super_diff 0.11.0 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -166
- data/lib/super_diff/active_record/differs/active_record_relation.rb +1 -1
- data/lib/super_diff/active_record/inspection_tree_builders/active_record_model.rb +57 -0
- data/lib/super_diff/active_record/inspection_tree_builders/active_record_relation.rb +34 -0
- data/lib/super_diff/active_record/inspection_tree_builders.rb +14 -0
- data/lib/super_diff/active_record/monkey_patches.rb +6 -3
- data/lib/super_diff/active_record/object_inspection.rb +16 -4
- data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +6 -2
- data/lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb +1 -1
- data/lib/super_diff/active_record/operation_tree_flatteners/active_record_relation.rb +1 -1
- data/lib/super_diff/active_record/operation_trees/active_record_relation.rb +1 -1
- data/lib/super_diff/active_record.rb +12 -16
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +1 -1
- data/lib/super_diff/active_support/inspection_tree_builders/hash_with_indifferent_access.rb +44 -0
- data/lib/super_diff/active_support/inspection_tree_builders/ordered_options.rb +44 -0
- data/lib/super_diff/active_support/inspection_tree_builders.rb +14 -0
- data/lib/super_diff/active_support/object_inspection.rb +16 -4
- data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +1 -1
- data/lib/super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access.rb +1 -1
- data/lib/super_diff/active_support/operation_trees/hash_with_indifferent_access.rb +1 -1
- data/lib/super_diff/active_support.rb +11 -15
- data/lib/super_diff/basic/diff_formatters/collection.rb +135 -0
- data/lib/super_diff/basic/diff_formatters/multiline_string.rb +34 -0
- data/lib/super_diff/basic/diff_formatters.rb +11 -0
- data/lib/super_diff/basic/differs/array.rb +17 -0
- data/lib/super_diff/basic/differs/custom_object.rb +19 -0
- data/lib/super_diff/basic/differs/date_like.rb +17 -0
- data/lib/super_diff/basic/differs/default_object.rb +24 -0
- data/lib/super_diff/basic/differs/hash.rb +17 -0
- data/lib/super_diff/basic/differs/multiline_string.rb +18 -0
- data/lib/super_diff/basic/differs/time_like.rb +17 -0
- data/lib/super_diff/basic/differs.rb +24 -0
- data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/array.rb +3 -3
- data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/custom_object.rb +3 -3
- data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/date_like.rb +3 -3
- data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/default_object.rb +5 -7
- data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/hash.rb +3 -3
- data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/primitive.rb +3 -3
- data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/time_like.rb +3 -3
- data/lib/super_diff/basic/inspection_tree_builders.rb +20 -0
- data/lib/super_diff/basic/operation_tree_builders/array.rb +111 -0
- data/lib/super_diff/basic/operation_tree_builders/custom_object.rb +42 -0
- data/lib/super_diff/basic/operation_tree_builders/date_like.rb +17 -0
- data/lib/super_diff/basic/operation_tree_builders/default_object.rb +117 -0
- data/lib/super_diff/basic/operation_tree_builders/hash.rb +222 -0
- data/lib/super_diff/basic/operation_tree_builders/multiline_string.rb +90 -0
- data/lib/super_diff/basic/operation_tree_builders/time_like.rb +26 -0
- data/lib/super_diff/basic/operation_tree_builders.rb +34 -0
- data/lib/super_diff/basic/operation_tree_flatteners/array.rb +17 -0
- data/lib/super_diff/basic/operation_tree_flatteners/collection.rb +140 -0
- data/lib/super_diff/basic/operation_tree_flatteners/custom_object.rb +30 -0
- data/lib/super_diff/basic/operation_tree_flatteners/default_object.rb +32 -0
- data/lib/super_diff/basic/operation_tree_flatteners/hash.rb +35 -0
- data/lib/super_diff/basic/operation_tree_flatteners/multiline_string.rb +20 -0
- data/lib/super_diff/basic/operation_tree_flatteners.rb +24 -0
- data/lib/super_diff/basic/operation_trees/array.rb +17 -0
- data/lib/super_diff/basic/operation_trees/custom_object.rb +17 -0
- data/lib/super_diff/basic/operation_trees/default_object.rb +42 -0
- data/lib/super_diff/basic/operation_trees/hash.rb +17 -0
- data/lib/super_diff/basic/operation_trees/multiline_string.rb +17 -0
- data/lib/super_diff/basic/operation_trees.rb +25 -0
- data/lib/super_diff/basic.rb +48 -0
- data/lib/super_diff/{differs/base.rb → core/abstract_differ.rb} +2 -2
- data/lib/super_diff/core/abstract_inspection_tree_builder.rb +26 -0
- data/lib/super_diff/{operation_trees/base.rb → core/abstract_operation_tree.rb} +6 -2
- data/lib/super_diff/{operation_tree_builders/base.rb → core/abstract_operation_tree_builder.rb} +4 -8
- data/lib/super_diff/{operation_tree_flatteners/base.rb → core/abstract_operation_tree_flattener.rb} +2 -2
- data/lib/super_diff/{operations → core}/binary_operation.rb +1 -1
- data/lib/super_diff/core/colorized_document_extensions.rb +20 -0
- data/lib/super_diff/core/configuration.rb +192 -0
- data/lib/super_diff/core/differ_dispatcher.rb +31 -0
- data/lib/super_diff/core/gem_version.rb +47 -0
- data/lib/super_diff/core/helpers.rb +88 -0
- data/lib/super_diff/core/implementation_checks.rb +21 -0
- data/lib/super_diff/{object_inspection → core}/inspection_tree.rb +7 -6
- data/lib/super_diff/core/inspection_tree_builder_dispatcher.rb +23 -0
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_lines_when_rendering_to_lines.rb +9 -3
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_prefix_when_rendering_to_lines.rb +3 -3
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_prelude_when_rendering_to_lines.rb +3 -3
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_single_line.rb +3 -3
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/base.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/inspection.rb +7 -11
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/nesting.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/only_when.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/text.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_empty.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_non_empty.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_rendering_to_lines.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_rendering_to_string.rb +2 -2
- data/lib/super_diff/core/inspection_tree_nodes.rb +55 -0
- data/lib/super_diff/core/line.rb +85 -0
- data/lib/super_diff/{errors → core}/no_differ_available_error.rb +1 -1
- data/lib/super_diff/core/no_inspection_tree_builder_available_error.rb +21 -0
- data/lib/super_diff/core/no_operation_tree_available_error.rb +20 -0
- data/lib/super_diff/core/no_operation_tree_builder_available_error.rb +24 -0
- data/lib/super_diff/{operation_tree_builders/main.rb → core/operation_tree_builder_dispatcher.rb} +9 -13
- data/lib/super_diff/core/operation_tree_finder.rb +27 -0
- data/lib/super_diff/core/prefix_for_next_inspection_tree_node.rb +6 -0
- data/lib/super_diff/core/prelude_for_next_inspection_tree_node.rb +6 -0
- data/lib/super_diff/core/recursion_guard.rb +52 -0
- data/lib/super_diff/core/tiered_lines.rb +6 -0
- data/lib/super_diff/core/tiered_lines_elider.rb +472 -0
- data/lib/super_diff/core/tiered_lines_formatter.rb +77 -0
- data/lib/super_diff/{operations → core}/unary_operation.rb +1 -1
- data/lib/super_diff/core.rb +69 -0
- data/lib/super_diff/differs.rb +19 -12
- data/lib/super_diff/equality_matchers/array.rb +3 -3
- data/lib/super_diff/equality_matchers/default.rb +8 -3
- data/lib/super_diff/equality_matchers/hash.rb +3 -3
- data/lib/super_diff/equality_matchers/multiline_string.rb +3 -3
- data/lib/super_diff/equality_matchers/primitive.rb +3 -3
- data/lib/super_diff/equality_matchers/singleline_string.rb +2 -2
- data/lib/super_diff/errors.rb +12 -8
- data/lib/super_diff/object_inspection.rb +63 -14
- data/lib/super_diff/operation_tree_builders.rb +19 -15
- data/lib/super_diff/operation_tree_flatteners.rb +19 -16
- data/lib/super_diff/operation_trees.rb +19 -9
- data/lib/super_diff/operations.rb +12 -2
- data/lib/super_diff/rspec/augmented_matcher.rb +1 -1
- data/lib/super_diff/rspec/differ.rb +4 -5
- data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +1 -1
- data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
- data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
- data/lib/super_diff/rspec/differs/object_having_attributes.rb +1 -1
- data/lib/super_diff/rspec/inspection_tree_builders/collection_containing_exactly.rb +34 -0
- data/lib/super_diff/rspec/inspection_tree_builders/collection_including.rb +40 -0
- data/lib/super_diff/rspec/inspection_tree_builders/double.rb +100 -0
- data/lib/super_diff/rspec/inspection_tree_builders/generic_describable_matcher.rb +17 -0
- data/lib/super_diff/rspec/inspection_tree_builders/hash_including.rb +40 -0
- data/lib/super_diff/rspec/inspection_tree_builders/instance_of.rb +25 -0
- data/lib/super_diff/rspec/inspection_tree_builders/kind_of.rb +25 -0
- data/lib/super_diff/rspec/inspection_tree_builders/object_having_attributes.rb +34 -0
- data/lib/super_diff/rspec/inspection_tree_builders/primitive.rb +9 -0
- data/lib/super_diff/rspec/inspection_tree_builders/value_within.rb +30 -0
- data/lib/super_diff/rspec/inspection_tree_builders.rb +40 -0
- data/lib/super_diff/rspec/object_inspection.rb +14 -4
- data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +4 -4
- data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +1 -1
- data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +1 -1
- data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +2 -2
- data/lib/super_diff/rspec.rb +20 -18
- data/lib/super_diff/version.rb +1 -1
- data/lib/super_diff.rb +69 -21
- data/spec/examples.txt +704 -543
- data/spec/support/integration/helpers.rb +4 -1
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +1 -1
- data/spec/support/models/active_record/person.rb +8 -1
- data/spec/support/shared_examples/active_record.rb +5 -5
- data/spec/support/unit/helpers.rb +12 -1
- data/spec/support/unit/matchers/be_deprecated_in_favor_of.rb +39 -0
- data/spec/unit/active_record/object_inspection_spec.rb +5 -5
- data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/array_spec.rb +8 -8
- data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/custom_object_spec.rb +9 -9
- data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/default_object_spec.rb +9 -9
- data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/hash_spec.rb +8 -8
- data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/multiline_string_spec.rb +4 -4
- data/spec/unit/{helpers_spec.rb → core/helpers_spec.rb} +2 -2
- data/spec/unit/{tiered_lines_elider_spec.rb → core/tiered_lines_elider_spec.rb} +2 -2
- data/spec/unit/{tiered_lines_formatter_spec.rb → core/tiered_lines_formatter_spec.rb} +1 -1
- data/spec/unit/deprecations_spec.rb +176 -0
- data/spec/unit/equality_matchers/main_spec.rb +5 -5
- data/super_diff.gemspec +6 -0
- metadata +127 -115
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +0 -51
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +0 -36
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +0 -16
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +0 -46
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb +0 -46
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +0 -16
- data/lib/super_diff/colorized_document_extensions.rb +0 -18
- data/lib/super_diff/configuration.rb +0 -149
- data/lib/super_diff/diff_formatters/collection.rb +0 -132
- data/lib/super_diff/diff_formatters/multiline_string.rb +0 -31
- data/lib/super_diff/differs/array.rb +0 -15
- data/lib/super_diff/differs/custom_object.rb +0 -17
- data/lib/super_diff/differs/date_like.rb +0 -15
- data/lib/super_diff/differs/default_object.rb +0 -19
- data/lib/super_diff/differs/defaults.rb +0 -13
- data/lib/super_diff/differs/empty.rb +0 -13
- data/lib/super_diff/differs/hash.rb +0 -15
- data/lib/super_diff/differs/main.rb +0 -31
- data/lib/super_diff/differs/multiline_string.rb +0 -16
- data/lib/super_diff/differs/time_like.rb +0 -15
- data/lib/super_diff/gem_version.rb +0 -45
- data/lib/super_diff/helpers.rb +0 -86
- data/lib/super_diff/implementation_checks.rb +0 -19
- data/lib/super_diff/line.rb +0 -83
- data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +0 -27
- data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +0 -15
- data/lib/super_diff/object_inspection/inspection_tree_builders/main.rb +0 -30
- data/lib/super_diff/object_inspection/inspection_tree_builders.rb +0 -48
- data/lib/super_diff/object_inspection/nodes.rb +0 -50
- data/lib/super_diff/object_inspection/prefix_for_next_node.rb +0 -6
- data/lib/super_diff/object_inspection/prelude_for_next_node.rb +0 -6
- data/lib/super_diff/operation_tree_builders/array.rb +0 -107
- data/lib/super_diff/operation_tree_builders/custom_object.rb +0 -40
- data/lib/super_diff/operation_tree_builders/date_like.rb +0 -15
- data/lib/super_diff/operation_tree_builders/default_object.rb +0 -119
- data/lib/super_diff/operation_tree_builders/defaults.rb +0 -5
- data/lib/super_diff/operation_tree_builders/hash.rb +0 -218
- data/lib/super_diff/operation_tree_builders/multiline_string.rb +0 -86
- data/lib/super_diff/operation_tree_builders/time_like.rb +0 -24
- data/lib/super_diff/operation_tree_flatteners/array.rb +0 -15
- data/lib/super_diff/operation_tree_flatteners/collection.rb +0 -136
- data/lib/super_diff/operation_tree_flatteners/custom_object.rb +0 -28
- data/lib/super_diff/operation_tree_flatteners/default_object.rb +0 -31
- data/lib/super_diff/operation_tree_flatteners/hash.rb +0 -33
- data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +0 -18
- data/lib/super_diff/operation_trees/array.rb +0 -15
- data/lib/super_diff/operation_trees/custom_object.rb +0 -15
- data/lib/super_diff/operation_trees/default_object.rb +0 -40
- data/lib/super_diff/operation_trees/defaults.rb +0 -5
- data/lib/super_diff/operation_trees/hash.rb +0 -15
- data/lib/super_diff/operation_trees/main.rb +0 -35
- data/lib/super_diff/operation_trees/multiline_string.rb +0 -15
- data/lib/super_diff/recursion_guard.rb +0 -50
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb +0 -36
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +0 -42
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +0 -102
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher.rb +0 -19
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +0 -42
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +0 -27
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +0 -27
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +0 -36
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/primitive.rb +0 -10
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +0 -32
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +0 -48
- data/lib/super_diff/tiered_lines.rb +0 -4
- data/lib/super_diff/tiered_lines_elider.rb +0 -462
- data/lib/super_diff/tiered_lines_formatter.rb +0 -75
@@ -0,0 +1,55 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Core
|
3
|
+
module InspectionTreeNodes
|
4
|
+
autoload(
|
5
|
+
:AsLinesWhenRenderingToLines,
|
6
|
+
"super_diff/core/inspection_tree_nodes/as_lines_when_rendering_to_lines"
|
7
|
+
)
|
8
|
+
autoload(
|
9
|
+
:AsPrefixWhenRenderingToLines,
|
10
|
+
"super_diff/core/inspection_tree_nodes/as_prefix_when_rendering_to_lines"
|
11
|
+
)
|
12
|
+
autoload(
|
13
|
+
:AsPreludeWhenRenderingToLines,
|
14
|
+
"super_diff/core/inspection_tree_nodes/as_prelude_when_rendering_to_lines"
|
15
|
+
)
|
16
|
+
autoload(
|
17
|
+
:AsSingleLine,
|
18
|
+
"super_diff/core/inspection_tree_nodes/as_single_line"
|
19
|
+
)
|
20
|
+
autoload :Base, "super_diff/core/inspection_tree_nodes/base"
|
21
|
+
autoload :Inspection, "super_diff/core/inspection_tree_nodes/inspection"
|
22
|
+
autoload :Nesting, "super_diff/core/inspection_tree_nodes/nesting"
|
23
|
+
autoload :OnlyWhen, "super_diff/core/inspection_tree_nodes/only_when"
|
24
|
+
autoload :Text, "super_diff/core/inspection_tree_nodes/text"
|
25
|
+
autoload :WhenEmpty, "super_diff/core/inspection_tree_nodes/when_empty"
|
26
|
+
autoload(
|
27
|
+
:WhenNonEmpty,
|
28
|
+
"super_diff/core/inspection_tree_nodes/when_non_empty"
|
29
|
+
)
|
30
|
+
autoload(
|
31
|
+
:WhenRenderingToLines,
|
32
|
+
"super_diff/core/inspection_tree_nodes/when_rendering_to_lines"
|
33
|
+
)
|
34
|
+
autoload(
|
35
|
+
:WhenRenderingToString,
|
36
|
+
"super_diff/core/inspection_tree_nodes/when_rendering_to_string"
|
37
|
+
)
|
38
|
+
|
39
|
+
def self.registry
|
40
|
+
@_registry ||= [
|
41
|
+
AsLinesWhenRenderingToLines,
|
42
|
+
AsPrefixWhenRenderingToLines,
|
43
|
+
AsPreludeWhenRenderingToLines,
|
44
|
+
AsSingleLine,
|
45
|
+
Inspection,
|
46
|
+
Nesting,
|
47
|
+
OnlyWhen,
|
48
|
+
Text,
|
49
|
+
WhenRenderingToLines,
|
50
|
+
WhenRenderingToString
|
51
|
+
]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Core
|
3
|
+
class Line
|
4
|
+
extend AttrExtras.mixin
|
5
|
+
|
6
|
+
ICONS = { delete: "-", insert: "+", noop: " " }.freeze
|
7
|
+
COLORS = { insert: :actual, delete: :expected, noop: :plain }.freeze
|
8
|
+
|
9
|
+
rattr_initialize(
|
10
|
+
[
|
11
|
+
:type!,
|
12
|
+
:indentation_level!,
|
13
|
+
:value!,
|
14
|
+
prefix: "",
|
15
|
+
add_comma: false,
|
16
|
+
children: [],
|
17
|
+
elided: false,
|
18
|
+
collection_bookend: nil,
|
19
|
+
complete_bookend: nil
|
20
|
+
]
|
21
|
+
)
|
22
|
+
attr_query :add_comma?
|
23
|
+
attr_query :elided?
|
24
|
+
|
25
|
+
def clone_with(overrides = {})
|
26
|
+
self.class.new(
|
27
|
+
type: type,
|
28
|
+
indentation_level: indentation_level,
|
29
|
+
prefix: prefix,
|
30
|
+
value: value,
|
31
|
+
add_comma: add_comma?,
|
32
|
+
children: children,
|
33
|
+
elided: elided?,
|
34
|
+
collection_bookend: collection_bookend,
|
35
|
+
complete_bookend: complete_bookend,
|
36
|
+
**overrides
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def icon
|
41
|
+
ICONS.fetch(type)
|
42
|
+
end
|
43
|
+
|
44
|
+
def color
|
45
|
+
COLORS.fetch(type)
|
46
|
+
end
|
47
|
+
|
48
|
+
def with_comma
|
49
|
+
clone_with(add_comma: true)
|
50
|
+
end
|
51
|
+
|
52
|
+
def as_elided
|
53
|
+
clone_with(elided: true)
|
54
|
+
end
|
55
|
+
|
56
|
+
def with_value_prepended(prelude)
|
57
|
+
clone_with(value: prelude + value)
|
58
|
+
end
|
59
|
+
|
60
|
+
def with_value_appended(suffix)
|
61
|
+
clone_with(value: value + suffix)
|
62
|
+
end
|
63
|
+
|
64
|
+
def prefixed_with(prefix)
|
65
|
+
clone_with(prefix: prefix + self.prefix)
|
66
|
+
end
|
67
|
+
|
68
|
+
def with_complete_bookend(complete_bookend)
|
69
|
+
clone_with(complete_bookend: complete_bookend)
|
70
|
+
end
|
71
|
+
|
72
|
+
def opens_collection?
|
73
|
+
collection_bookend == :open
|
74
|
+
end
|
75
|
+
|
76
|
+
def closes_collection?
|
77
|
+
collection_bookend == :close
|
78
|
+
end
|
79
|
+
|
80
|
+
def complete_bookend?
|
81
|
+
complete_bookend != nil
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Core
|
3
|
+
class NoInspectionTreeBuilderAvailableError < StandardError
|
4
|
+
def self.create(object)
|
5
|
+
allocate.tap do |error|
|
6
|
+
error.object = object
|
7
|
+
error.__send__(:initialize)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_accessor :object
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
super(<<-MESSAGE)
|
15
|
+
There is no inspection tree builder available to handle a "value" of type
|
16
|
+
#{object.class}.
|
17
|
+
MESSAGE
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Core
|
3
|
+
class NoOperationTreeAvailableError < StandardError
|
4
|
+
def self.create(value)
|
5
|
+
allocate.tap do |error|
|
6
|
+
error.value = value
|
7
|
+
error.__send__(:initialize)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_accessor :value
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
super(<<-MESSAGE)
|
15
|
+
There is no operation tree available to handle a "value" of type #{value.class}.
|
16
|
+
MESSAGE
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Core
|
3
|
+
class NoOperationTreeBuilderAvailableError < StandardError
|
4
|
+
def self.create(expected, actual)
|
5
|
+
allocate.tap do |error|
|
6
|
+
error.expected = expected
|
7
|
+
error.actual = actual
|
8
|
+
error.__send__(:initialize)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_accessor :expected, :actual
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
super(<<-MESSAGE)
|
16
|
+
There is no operation tree builder available to handle an "expected" value of type
|
17
|
+
#{expected.class}
|
18
|
+
and an "actual" value of type
|
19
|
+
#{actual.class}.
|
20
|
+
MESSAGE
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/super_diff/{operation_tree_builders/main.rb → core/operation_tree_builder_dispatcher.rb}
RENAMED
@@ -1,14 +1,18 @@
|
|
1
1
|
module SuperDiff
|
2
|
-
module
|
3
|
-
class
|
2
|
+
module Core
|
3
|
+
class OperationTreeBuilderDispatcher
|
4
4
|
extend AttrExtras.mixin
|
5
5
|
|
6
|
-
method_object
|
6
|
+
method_object(
|
7
|
+
:expected,
|
8
|
+
:actual,
|
9
|
+
[:available_classes, raise_if_nothing_applies: true]
|
10
|
+
)
|
7
11
|
|
8
12
|
def call
|
9
13
|
if resolved_class
|
10
14
|
resolved_class.call(expected: expected, actual: actual)
|
11
|
-
elsif
|
15
|
+
elsif raise_if_nothing_applies?
|
12
16
|
raise NoOperationTreeBuilderAvailableError.create(expected, actual)
|
13
17
|
else
|
14
18
|
nil
|
@@ -17,19 +21,11 @@ module SuperDiff
|
|
17
21
|
|
18
22
|
private
|
19
23
|
|
20
|
-
attr_query :
|
24
|
+
attr_query :raise_if_nothing_applies?
|
21
25
|
|
22
26
|
def resolved_class
|
23
27
|
available_classes.find { |klass| klass.applies_to?(expected, actual) }
|
24
28
|
end
|
25
|
-
|
26
|
-
def available_classes
|
27
|
-
classes =
|
28
|
-
SuperDiff.configuration.extra_operation_tree_builder_classes +
|
29
|
-
DEFAULTS
|
30
|
-
|
31
|
-
all_or_nothing? ? classes + [DefaultObject] : classes
|
32
|
-
end
|
33
29
|
end
|
34
30
|
end
|
35
31
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Core
|
3
|
+
class OperationTreeFinder
|
4
|
+
extend AttrExtras.mixin
|
5
|
+
|
6
|
+
method_object :value, [:available_classes]
|
7
|
+
|
8
|
+
def call
|
9
|
+
if resolved_class
|
10
|
+
begin
|
11
|
+
resolved_class.new([], underlying_object: value)
|
12
|
+
rescue ArgumentError
|
13
|
+
resolved_class.new([])
|
14
|
+
end
|
15
|
+
else
|
16
|
+
raise NoOperationTreeAvailableError.create(value)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def resolved_class
|
23
|
+
available_classes.find { |klass| klass.applies_to?(value) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "set"
|
2
|
+
|
3
|
+
module SuperDiff
|
4
|
+
module Core
|
5
|
+
module RecursionGuard
|
6
|
+
RECURSION_GUARD_KEY = "super_diff_recursion_guard_key".freeze
|
7
|
+
PLACEHOLDER = "∙∙∙".freeze
|
8
|
+
|
9
|
+
def self.guarding_recursion_of(*objects, &block)
|
10
|
+
already_seen_objects, first_seen_objects =
|
11
|
+
objects.partition do |object|
|
12
|
+
!SuperDiff.primitive?(object) && already_seen?(object)
|
13
|
+
end
|
14
|
+
|
15
|
+
first_seen_objects.each do |object|
|
16
|
+
already_seen_object_ids.add(object.object_id)
|
17
|
+
end
|
18
|
+
|
19
|
+
result =
|
20
|
+
if block.arity > 0
|
21
|
+
block.call(already_seen_objects.any?)
|
22
|
+
else
|
23
|
+
block.call
|
24
|
+
end
|
25
|
+
|
26
|
+
first_seen_objects.each do |object|
|
27
|
+
already_seen_object_ids.delete(object.object_id)
|
28
|
+
end
|
29
|
+
|
30
|
+
result
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.substituting_recursion_of(*objects)
|
34
|
+
guarding_recursion_of(*objects) do |already_seen|
|
35
|
+
if already_seen
|
36
|
+
PLACEHOLDER
|
37
|
+
else
|
38
|
+
yield
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.already_seen?(object)
|
44
|
+
already_seen_object_ids.include?(object.object_id)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.already_seen_object_ids
|
48
|
+
Thread.current[RECURSION_GUARD_KEY] ||= Set.new
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|