super_diff 0.10.0 → 0.12.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.
Potentially problematic release.
This version of super_diff might be problematic. Click here for more details.
- 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 -14
- 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/basic/inspection_tree_builders/array.rb +53 -0
- data/lib/super_diff/basic/inspection_tree_builders/custom_object.rb +41 -0
- data/lib/super_diff/basic/inspection_tree_builders/date_like.rb +51 -0
- data/lib/super_diff/basic/inspection_tree_builders/default_object.rb +77 -0
- data/lib/super_diff/basic/inspection_tree_builders/hash.rb +63 -0
- data/lib/super_diff/basic/inspection_tree_builders/primitive.rb +19 -0
- data/lib/super_diff/basic/inspection_tree_builders/time_like.rb +58 -0
- 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 +33 -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 +32 -26
- 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 +12 -5
- 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/{errors/no_operational_sequencer_available_error.rb → core/no_operation_tree_builder_available_error.rb} +6 -4
- 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 -11
- 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 -12
- data/lib/super_diff/object_inspection.rb +63 -14
- data/lib/super_diff/operation_tree_builders.rb +19 -14
- 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/matcher_text_builders/raise_error.rb +3 -7
- data/lib/super_diff/rspec/monkey_patches.rb +59 -8
- 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 +28 -25
- data/lib/super_diff/version.rb +1 -1
- data/lib/super_diff.rb +78 -21
- data/spec/examples.txt +704 -493
- data/spec/integration/rails/engines_spec.rb +8 -3
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +19 -19
- data/spec/integration/rspec/eq_matcher_spec.rb +111 -39
- data/spec/integration/rspec/generic_describable_matchers_spec.rb +177 -0
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +25 -25
- data/spec/integration/rspec/include_matcher_spec.rb +23 -23
- data/spec/integration/rspec/magic_metadata_spec.rb +51 -0
- data/spec/integration/rspec/match_array_matcher_spec.rb +30 -30
- data/spec/integration/rspec/match_matcher_spec.rb +93 -93
- data/spec/integration/rspec/raise_error_matcher_spec.rb +813 -69
- data/spec/internal/log/test.log +0 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/integration/helpers.rb +19 -11
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +1 -1
- data/spec/support/integration/matchers.rb +34 -0
- data/spec/support/integration/test_programs/base.rb +6 -6
- data/spec/support/integration/test_programs/rspec_rails_engine.rb +3 -13
- data/spec/support/models/active_record/person.rb +8 -1
- data/spec/support/shared_examples/active_record.rb +38 -38
- data/spec/support/shared_examples/active_support.rb +125 -4
- data/spec/support/shared_examples/elided_diffs.rb +48 -48
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +88 -88
- data/spec/support/shared_examples/key.rb +10 -10
- 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/active_support/object_inspection_spec.rb +170 -0
- 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/spec/unit/rspec/matchers/raise_error_spec.rb +43 -11
- data/spec/unit/rspec/object_inspection/rspec_matcher_spec.rb +91 -0
- data/spec/unit/rspec/object_inspection_spec.rb +2 -2
- data/spec/unit/super_diff_spec.rb +64 -0
- data/super_diff.gemspec +6 -0
- metadata +137 -112
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +0 -39
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +0 -27
- 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 -31
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +0 -12
- 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/default_object.rb +0 -19
- data/lib/super_diff/differs/defaults.rb +0 -12
- 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/errors/no_diff_formatter_available_error.rb +0 -21
- 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/array.rb +0 -34
- data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +0 -27
- data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +0 -31
- data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +0 -54
- data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +0 -14
- data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +0 -38
- data/lib/super_diff/object_inspection/inspection_tree_builders/main.rb +0 -30
- data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +0 -21
- data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +0 -47
- data/lib/super_diff/object_inspection/inspection_tree_builders.rb +0 -44
- 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/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 -29
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +0 -36
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +0 -98
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +0 -37
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +0 -28
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +0 -28
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +0 -29
- 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 -33
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +0 -44
- 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
data/lib/super_diff/helpers.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
module SuperDiff
|
2
|
-
module Helpers
|
3
|
-
extend self
|
4
|
-
|
5
|
-
# TODO: Simplify this
|
6
|
-
def style(*args, color_enabled: true, **opts, &block)
|
7
|
-
klass =
|
8
|
-
if color_enabled && Csi.color_enabled?
|
9
|
-
Csi::ColorizedDocument
|
10
|
-
else
|
11
|
-
Csi::UncolorizedDocument
|
12
|
-
end
|
13
|
-
|
14
|
-
document = klass.new.extend(ColorizedDocumentExtensions)
|
15
|
-
|
16
|
-
if block
|
17
|
-
document.__send__(:evaluate_block, &block)
|
18
|
-
else
|
19
|
-
document.colorize(*args, **opts)
|
20
|
-
end
|
21
|
-
|
22
|
-
document
|
23
|
-
end
|
24
|
-
|
25
|
-
def plural_type_for(value)
|
26
|
-
case value
|
27
|
-
when Numeric
|
28
|
-
"numbers"
|
29
|
-
when String
|
30
|
-
"strings"
|
31
|
-
when Symbol
|
32
|
-
"symbols"
|
33
|
-
else
|
34
|
-
"objects"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def jruby?
|
39
|
-
defined?(JRUBY_VERSION)
|
40
|
-
end
|
41
|
-
|
42
|
-
def ruby_version_matches?(version_string)
|
43
|
-
Gem::Requirement.new(version_string).satisfied_by?(
|
44
|
-
Gem::Version.new(RUBY_VERSION)
|
45
|
-
)
|
46
|
-
end
|
47
|
-
|
48
|
-
if jruby?
|
49
|
-
def object_address_for(object)
|
50
|
-
# Source: <https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/RubyBasicObject.java>
|
51
|
-
"0x%x" % object.hash
|
52
|
-
end
|
53
|
-
elsif ruby_version_matches?(">= 2.7.0")
|
54
|
-
require "json"
|
55
|
-
require "objspace"
|
56
|
-
|
57
|
-
def object_address_for(object)
|
58
|
-
# Sources: <https://bugs.ruby-lang.org/issues/15408> and <https://bugs.ruby-lang.org/issues/15626#Object-ID>
|
59
|
-
json = JSON.parse(ObjectSpace.dump(object))
|
60
|
-
json.is_a?(Hash) ? "0x%016x" % Integer(json["address"], 16) : ""
|
61
|
-
end
|
62
|
-
else
|
63
|
-
def object_address_for(object)
|
64
|
-
"0x%016x" % (object.object_id * 2)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def with_slice_of_array_replaced(array, range, replacement)
|
69
|
-
beginning =
|
70
|
-
if range.begin > 0
|
71
|
-
array[Range.new(0, range.begin - 1)]
|
72
|
-
else
|
73
|
-
[]
|
74
|
-
end
|
75
|
-
|
76
|
-
ending =
|
77
|
-
if range.end <= array.length - 1
|
78
|
-
array[Range.new(range.end + 1, array.length - 1)]
|
79
|
-
else
|
80
|
-
[]
|
81
|
-
end
|
82
|
-
|
83
|
-
beginning + [replacement] + ending
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module SuperDiff
|
2
|
-
module ImplementationChecks
|
3
|
-
protected def unimplemented_instance_method!
|
4
|
-
raise(
|
5
|
-
NotImplementedError,
|
6
|
-
"#{self.class} must implement ##{caller_locations(1, 1).first.label}",
|
7
|
-
caller(1)
|
8
|
-
)
|
9
|
-
end
|
10
|
-
|
11
|
-
protected def unimplemented_class_method!
|
12
|
-
raise(
|
13
|
-
NotImplementedError,
|
14
|
-
"#{self} must implement .#{caller_locations(1, 1).first.label}",
|
15
|
-
caller(1)
|
16
|
-
)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
data/lib/super_diff/line.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
module SuperDiff
|
2
|
-
class Line
|
3
|
-
extend AttrExtras.mixin
|
4
|
-
|
5
|
-
ICONS = { delete: "-", insert: "+", noop: " " }.freeze
|
6
|
-
COLORS = { insert: :actual, delete: :expected, noop: :plain }.freeze
|
7
|
-
|
8
|
-
rattr_initialize(
|
9
|
-
[
|
10
|
-
:type!,
|
11
|
-
:indentation_level!,
|
12
|
-
:value!,
|
13
|
-
prefix: "",
|
14
|
-
add_comma: false,
|
15
|
-
children: [],
|
16
|
-
elided: false,
|
17
|
-
collection_bookend: nil,
|
18
|
-
complete_bookend: nil
|
19
|
-
]
|
20
|
-
)
|
21
|
-
attr_query :add_comma?
|
22
|
-
attr_query :elided?
|
23
|
-
|
24
|
-
def clone_with(overrides = {})
|
25
|
-
self.class.new(
|
26
|
-
type: type,
|
27
|
-
indentation_level: indentation_level,
|
28
|
-
prefix: prefix,
|
29
|
-
value: value,
|
30
|
-
add_comma: add_comma?,
|
31
|
-
children: children,
|
32
|
-
elided: elided?,
|
33
|
-
collection_bookend: collection_bookend,
|
34
|
-
complete_bookend: complete_bookend,
|
35
|
-
**overrides
|
36
|
-
)
|
37
|
-
end
|
38
|
-
|
39
|
-
def icon
|
40
|
-
ICONS.fetch(type)
|
41
|
-
end
|
42
|
-
|
43
|
-
def color
|
44
|
-
COLORS.fetch(type)
|
45
|
-
end
|
46
|
-
|
47
|
-
def with_comma
|
48
|
-
clone_with(add_comma: true)
|
49
|
-
end
|
50
|
-
|
51
|
-
def as_elided
|
52
|
-
clone_with(elided: true)
|
53
|
-
end
|
54
|
-
|
55
|
-
def with_value_prepended(prelude)
|
56
|
-
clone_with(value: prelude + value)
|
57
|
-
end
|
58
|
-
|
59
|
-
def with_value_appended(suffix)
|
60
|
-
clone_with(value: value + suffix)
|
61
|
-
end
|
62
|
-
|
63
|
-
def prefixed_with(prefix)
|
64
|
-
clone_with(prefix: prefix + self.prefix)
|
65
|
-
end
|
66
|
-
|
67
|
-
def with_complete_bookend(complete_bookend)
|
68
|
-
clone_with(complete_bookend: complete_bookend)
|
69
|
-
end
|
70
|
-
|
71
|
-
def opens_collection?
|
72
|
-
collection_bookend == :open
|
73
|
-
end
|
74
|
-
|
75
|
-
def closes_collection?
|
76
|
-
collection_bookend == :close
|
77
|
-
end
|
78
|
-
|
79
|
-
def complete_bookend?
|
80
|
-
complete_bookend != nil
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,34 +0,0 @@
|
|
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 { add_text "[]" }
|
16
|
-
end
|
17
|
-
|
18
|
-
only_when nonempty do
|
19
|
-
as_lines_when_rendering_to_lines(collection_bookend: :open) do
|
20
|
-
add_text "["
|
21
|
-
end
|
22
|
-
|
23
|
-
nested { |array| insert_array_inspection_of(array) }
|
24
|
-
|
25
|
-
as_lines_when_rendering_to_lines(collection_bookend: :close) do
|
26
|
-
add_text "]"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,27 +0,0 @@
|
|
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
|
@@ -1,31 +0,0 @@
|
|
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 { |object| "#<#{object.class} " }
|
13
|
-
|
14
|
-
when_rendering_to_lines { add_text "{" }
|
15
|
-
end
|
16
|
-
|
17
|
-
nested do |object|
|
18
|
-
insert_hash_inspection_of(object.attributes_for_super_diff)
|
19
|
-
end
|
20
|
-
|
21
|
-
as_lines_when_rendering_to_lines(collection_bookend: :close) do
|
22
|
-
when_rendering_to_lines { add_text "}" }
|
23
|
-
|
24
|
-
add_text ">"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,54 +0,0 @@
|
|
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
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
only_when nonempty do
|
24
|
-
as_lines_when_rendering_to_lines(collection_bookend: :open) do
|
25
|
-
add_text do |object|
|
26
|
-
"#<#{object.class.name}:" +
|
27
|
-
SuperDiff::Helpers.object_address_for(object)
|
28
|
-
end
|
29
|
-
|
30
|
-
when_rendering_to_lines { add_text " {" }
|
31
|
-
end
|
32
|
-
|
33
|
-
when_rendering_to_string { add_text " " }
|
34
|
-
|
35
|
-
nested do |object|
|
36
|
-
insert_separated_list(object.instance_variables.sort) do |name|
|
37
|
-
as_prefix_when_rendering_to_lines { add_text "#{name}=" }
|
38
|
-
|
39
|
-
add_inspection_of object.instance_variable_get(name)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
as_lines_when_rendering_to_lines(collection_bookend: :close) do
|
44
|
-
when_rendering_to_lines { add_text "}" }
|
45
|
-
|
46
|
-
add_text ">"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,38 +0,0 @@
|
|
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 { add_text "{}" }
|
16
|
-
end
|
17
|
-
|
18
|
-
only_when nonempty do
|
19
|
-
as_lines_when_rendering_to_lines(collection_bookend: :open) do
|
20
|
-
add_text "{"
|
21
|
-
end
|
22
|
-
|
23
|
-
when_rendering_to_string { add_text " " }
|
24
|
-
|
25
|
-
nested { |hash| insert_hash_inspection_of(hash) }
|
26
|
-
|
27
|
-
when_rendering_to_string { add_text " " }
|
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
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module SuperDiff
|
2
|
-
module ObjectInspection
|
3
|
-
module InspectionTreeBuilders
|
4
|
-
class Main
|
5
|
-
extend AttrExtras.mixin
|
6
|
-
|
7
|
-
method_object :object
|
8
|
-
|
9
|
-
def call
|
10
|
-
if resolved_class
|
11
|
-
resolved_class.call(object)
|
12
|
-
else
|
13
|
-
raise NoInspectorAvailableError.create(object)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def resolved_class
|
20
|
-
available_classes.find { |klass| klass.applies_to?(object) }
|
21
|
-
end
|
22
|
-
|
23
|
-
def available_classes
|
24
|
-
SuperDiff.configuration.extra_inspection_tree_builder_classes +
|
25
|
-
DEFAULTS
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,21 +0,0 @@
|
|
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,47 +0,0 @@
|
|
1
|
-
module SuperDiff
|
2
|
-
module ObjectInspection
|
3
|
-
module InspectionTreeBuilders
|
4
|
-
class TimeLike < Base
|
5
|
-
def self.applies_to?(value)
|
6
|
-
SuperDiff.time_like?(value)
|
7
|
-
end
|
8
|
-
|
9
|
-
def call
|
10
|
-
InspectionTree.new do
|
11
|
-
as_lines_when_rendering_to_lines(collection_bookend: :open) do
|
12
|
-
add_text { |time| "#<#{time.class} " }
|
13
|
-
|
14
|
-
when_rendering_to_lines { add_text "{" }
|
15
|
-
end
|
16
|
-
|
17
|
-
when_rendering_to_string do
|
18
|
-
add_text do |time|
|
19
|
-
time.strftime("%Y-%m-%d %H:%M:%S") +
|
20
|
-
(time.subsec == 0 ? "" : "+#{time.subsec.inspect}") + " " +
|
21
|
-
time.strftime("%:z") + (time.zone ? " (#{time.zone})" : "")
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
when_rendering_to_lines do
|
26
|
-
nested do |time|
|
27
|
-
insert_separated_list(
|
28
|
-
%i[year month day hour min sec subsec zone utc_offset]
|
29
|
-
) do |name|
|
30
|
-
add_text name.to_s
|
31
|
-
add_text ": "
|
32
|
-
add_inspection_of time.public_send(name)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
as_lines_when_rendering_to_lines(collection_bookend: :close) do
|
38
|
-
when_rendering_to_lines { add_text "}" }
|
39
|
-
|
40
|
-
add_text ">"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,44 +0,0 @@
|
|
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"
|
@@ -1,50 +0,0 @@
|
|
1
|
-
module SuperDiff
|
2
|
-
module ObjectInspection
|
3
|
-
module Nodes
|
4
|
-
autoload(
|
5
|
-
:AsLinesWhenRenderingToLines,
|
6
|
-
"super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines"
|
7
|
-
)
|
8
|
-
autoload(
|
9
|
-
:AsPrefixWhenRenderingToLines,
|
10
|
-
"super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines"
|
11
|
-
)
|
12
|
-
autoload(
|
13
|
-
:AsPreludeWhenRenderingToLines,
|
14
|
-
"super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines"
|
15
|
-
)
|
16
|
-
autoload(
|
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"
|
32
|
-
)
|
33
|
-
|
34
|
-
def self.registry
|
35
|
-
@_registry ||= [
|
36
|
-
AsLinesWhenRenderingToLines,
|
37
|
-
AsPrefixWhenRenderingToLines,
|
38
|
-
AsPreludeWhenRenderingToLines,
|
39
|
-
AsSingleLine,
|
40
|
-
Inspection,
|
41
|
-
Nesting,
|
42
|
-
OnlyWhen,
|
43
|
-
Text,
|
44
|
-
WhenRenderingToLines,
|
45
|
-
WhenRenderingToString
|
46
|
-
]
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|