super_diff 0.5.3 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +46 -20
- data/lib/super_diff.rb +46 -7
- data/lib/super_diff/active_record.rb +7 -7
- data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -13
- data/lib/super_diff/active_record/object_inspection.rb +2 -6
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +16 -0
- data/lib/super_diff/active_record/object_inspection/{inspectors → inspection_tree_builders}/active_record_model.rb +19 -20
- data/lib/super_diff/active_record/object_inspection/{inspectors → inspection_tree_builders}/active_record_relation.rb +9 -8
- data/lib/super_diff/active_record/operation_tree_flatteners.rb +10 -0
- data/lib/super_diff/active_record/operation_tree_flatteners/active_record_relation.rb +17 -0
- data/lib/super_diff/active_record/operation_trees/active_record_relation.rb +8 -7
- data/lib/super_diff/active_support.rb +8 -8
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -13
- data/lib/super_diff/active_support/object_inspection.rb +2 -6
- data/lib/super_diff/active_support/object_inspection/{inspectors.rb → inspection_tree_builders.rb} +2 -2
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +37 -0
- data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +17 -0
- data/lib/super_diff/active_support/operation_tree_flatteners.rb +10 -0
- data/lib/super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access.rb +17 -0
- data/lib/super_diff/active_support/operation_trees/hash_with_indifferent_access.rb +4 -7
- data/lib/super_diff/colorized_document_extensions.rb +9 -6
- data/lib/super_diff/configuration.rb +102 -19
- data/lib/super_diff/csi.rb +1 -1
- data/lib/super_diff/csi/four_bit_color.rb +0 -2
- data/lib/super_diff/diff_formatters/collection.rb +2 -2
- data/lib/super_diff/diff_formatters/multiline_string.rb +4 -4
- data/lib/super_diff/differs/array.rb +1 -1
- data/lib/super_diff/differs/base.rb +3 -21
- data/lib/super_diff/differs/custom_object.rb +1 -1
- data/lib/super_diff/differs/default_object.rb +1 -1
- data/lib/super_diff/differs/hash.rb +1 -1
- data/lib/super_diff/differs/main.rb +1 -7
- data/lib/super_diff/differs/multiline_string.rb +1 -1
- data/lib/super_diff/differs/time_like.rb +1 -1
- data/lib/super_diff/equality_matchers/array.rb +4 -4
- data/lib/super_diff/equality_matchers/default.rb +4 -4
- data/lib/super_diff/equality_matchers/hash.rb +4 -4
- data/lib/super_diff/equality_matchers/multiline_string.rb +4 -4
- data/lib/super_diff/equality_matchers/primitive.rb +6 -9
- data/lib/super_diff/equality_matchers/singleline_string.rb +4 -4
- data/lib/super_diff/gem_version.rb +45 -0
- data/lib/super_diff/helpers.rb +52 -2
- data/lib/super_diff/line.rb +83 -0
- data/lib/super_diff/object_inspection.rb +12 -9
- data/lib/super_diff/object_inspection/inspection_tree.rb +183 -81
- data/lib/super_diff/object_inspection/inspection_tree_builders.rb +44 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +38 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +27 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +37 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +63 -0
- data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/defaults.rb +1 -2
- data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +46 -0
- data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/main.rb +5 -10
- data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +21 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +64 -0
- data/lib/super_diff/object_inspection/nodes.rb +33 -32
- data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +97 -0
- data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +27 -0
- data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +27 -0
- data/lib/super_diff/object_inspection/nodes/as_single_line.rb +33 -0
- data/lib/super_diff/object_inspection/nodes/base.rb +55 -20
- data/lib/super_diff/object_inspection/nodes/inspection.rb +47 -7
- data/lib/super_diff/object_inspection/nodes/nesting.rb +16 -5
- data/lib/super_diff/object_inspection/nodes/only_when.rb +54 -0
- data/lib/super_diff/object_inspection/nodes/text.rb +16 -2
- data/lib/super_diff/object_inspection/nodes/when_empty.rb +21 -6
- data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +20 -5
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +27 -0
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +27 -0
- data/lib/super_diff/object_inspection/prefix_for_next_node.rb +6 -0
- data/lib/super_diff/object_inspection/prelude_for_next_node.rb +6 -0
- data/lib/super_diff/operation_tree_builders/array.rb +7 -10
- data/lib/super_diff/operation_tree_builders/base.rb +6 -6
- data/lib/super_diff/operation_tree_builders/custom_object.rb +5 -2
- data/lib/super_diff/operation_tree_builders/default_object.rb +1 -1
- data/lib/super_diff/operation_tree_builders/defaults.rb +1 -1
- data/lib/super_diff/operation_tree_builders/hash.rb +1 -8
- data/lib/super_diff/operation_tree_builders/multiline_string.rb +2 -6
- data/lib/super_diff/operation_tree_builders/time_like.rb +2 -2
- data/lib/super_diff/operation_tree_flatteners.rb +20 -0
- data/lib/super_diff/operation_tree_flatteners/array.rb +15 -0
- data/lib/super_diff/operation_tree_flatteners/base.rb +54 -0
- data/lib/super_diff/operation_tree_flatteners/collection.rb +139 -0
- data/lib/super_diff/operation_tree_flatteners/custom_object.rb +28 -0
- data/lib/super_diff/operation_tree_flatteners/default_object.rb +32 -0
- data/lib/super_diff/operation_tree_flatteners/hash.rb +41 -0
- data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +17 -0
- data/lib/super_diff/operation_trees/array.rb +4 -7
- data/lib/super_diff/operation_trees/base.rb +39 -16
- data/lib/super_diff/operation_trees/custom_object.rb +4 -8
- data/lib/super_diff/operation_trees/default_object.rb +28 -13
- data/lib/super_diff/operation_trees/hash.rb +4 -7
- data/lib/super_diff/operation_trees/main.rb +1 -1
- data/lib/super_diff/operation_trees/multiline_string.rb +4 -7
- data/lib/super_diff/operations/binary_operation.rb +1 -6
- data/lib/super_diff/operations/unary_operation.rb +2 -30
- data/lib/super_diff/recursion_guard.rb +3 -3
- data/lib/super_diff/rspec.rb +41 -13
- data/lib/super_diff/rspec/differs/collection_including.rb +4 -2
- data/lib/super_diff/rspec/differs/hash_including.rb +4 -2
- data/lib/super_diff/rspec/matcher_text_builders/base.rb +7 -7
- data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +6 -6
- data/lib/super_diff/rspec/matcher_text_builders/contain_exactly.rb +1 -1
- data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +4 -4
- data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +1 -1
- data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +5 -5
- data/lib/super_diff/rspec/monkey_patches.rb +353 -306
- data/lib/super_diff/rspec/object_inspection.rb +4 -1
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +44 -0
- data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/collection_containing_exactly.rb +9 -8
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +34 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +103 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +36 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +26 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +26 -0
- data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/object_having_attributes.rb +10 -12
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/primitive.rb +10 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +33 -0
- data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +12 -4
- data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +10 -3
- data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +10 -3
- data/lib/super_diff/tiered_lines.rb +4 -0
- data/lib/super_diff/tiered_lines_elider.rb +490 -0
- data/lib/super_diff/tiered_lines_formatter.rb +79 -0
- data/lib/super_diff/version.rb +1 -1
- data/spec/examples.txt +407 -5
- data/spec/integration/rails/active_support_spec.rb +19 -0
- data/spec/integration/rspec/be_falsey_matcher_spec.rb +10 -10
- data/spec/integration/rspec/be_matcher_spec.rb +100 -100
- data/spec/integration/rspec/be_nil_matcher_spec.rb +10 -10
- data/spec/integration/rspec/be_predicate_matcher_spec.rb +103 -103
- data/spec/integration/rspec/be_truthy_matcher_spec.rb +10 -10
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +113 -107
- data/spec/integration/rspec/eq_matcher_spec.rb +223 -277
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +138 -129
- data/spec/integration/rspec/have_predicate_matcher_spec.rb +65 -65
- data/spec/integration/rspec/include_matcher_spec.rb +73 -73
- data/spec/integration/rspec/match_array_matcher_spec.rb +126 -119
- data/spec/integration/rspec/match_matcher_spec.rb +362 -274
- data/spec/integration/rspec/raise_error_matcher_spec.rb +86 -86
- data/spec/integration/rspec/respond_to_matcher_spec.rb +240 -240
- data/spec/integration/rspec/third_party_matcher_spec.rb +8 -8
- data/spec/integration/rspec/unhandled_errors_spec.rb +5 -5
- data/spec/spec_helper.rb +33 -13
- data/spec/support/command_runner.rb +15 -25
- data/spec/support/helpers.rb +21 -0
- data/spec/support/integration/helpers.rb +8 -2
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +4 -4
- data/spec/support/integration/test_programs/base.rb +38 -10
- data/spec/support/integration/test_programs/rspec_active_record.rb +1 -1
- data/spec/support/integration/test_programs/rspec_active_support.rb +17 -0
- data/spec/support/integration/test_programs/rspec_rails.rb +1 -1
- data/spec/support/shared_examples/active_record.rb +109 -108
- data/spec/support/shared_examples/active_support.rb +65 -0
- data/spec/support/shared_examples/elided_diffs.rb +914 -0
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +196 -232
- data/spec/support/unit/helpers.rb +15 -0
- data/spec/support/unit/matchers/match_output.rb +41 -0
- data/spec/unit/active_record/object_inspection_spec.rb +273 -0
- data/spec/unit/equality_matchers/main_spec.rb +445 -465
- data/spec/unit/helpers_spec.rb +61 -0
- data/spec/unit/operation_tree_flatteners/array_spec.rb +604 -0
- data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +667 -0
- data/spec/unit/operation_tree_flatteners/default_object_spec.rb +687 -0
- data/spec/unit/operation_tree_flatteners/hash_spec.rb +632 -0
- data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +121 -0
- data/spec/unit/rspec/object_inspection_spec.rb +446 -0
- data/spec/unit/super_diff_spec.rb +1958 -0
- data/spec/unit/tiered_lines_elider_spec.rb +6356 -0
- data/spec/unit/tiered_lines_formatter_spec.rb +193 -0
- data/super_diff.gemspec +1 -1
- metadata +95 -50
- data/lib/super_diff/active_record/diff_formatters.rb +0 -10
- data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +0 -23
- data/lib/super_diff/active_record/object_inspection/inspectors.rb +0 -16
- data/lib/super_diff/active_support/diff_formatters.rb +0 -10
- data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +0 -36
- data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +0 -28
- data/lib/super_diff/diff_formatters.rb +0 -14
- data/lib/super_diff/diff_formatters/array.rb +0 -21
- data/lib/super_diff/diff_formatters/base.rb +0 -33
- data/lib/super_diff/diff_formatters/custom_object.rb +0 -30
- data/lib/super_diff/diff_formatters/default_object.rb +0 -46
- data/lib/super_diff/diff_formatters/defaults.rb +0 -10
- data/lib/super_diff/diff_formatters/hash.rb +0 -34
- data/lib/super_diff/diff_formatters/main.rb +0 -41
- data/lib/super_diff/object_inspection/inspectors.rb +0 -23
- data/lib/super_diff/object_inspection/inspectors/array.rb +0 -32
- data/lib/super_diff/object_inspection/inspectors/base.rb +0 -36
- data/lib/super_diff/object_inspection/inspectors/custom_object.rb +0 -37
- data/lib/super_diff/object_inspection/inspectors/default_object.rb +0 -61
- data/lib/super_diff/object_inspection/inspectors/hash.rb +0 -32
- data/lib/super_diff/object_inspection/inspectors/primitive.rb +0 -28
- data/lib/super_diff/object_inspection/inspectors/string.rb +0 -23
- data/lib/super_diff/object_inspection/inspectors/time_like.rb +0 -23
- data/lib/super_diff/object_inspection/nodes/break.rb +0 -15
- data/lib/super_diff/object_inspection/nodes/when_multiline.rb +0 -22
- data/lib/super_diff/object_inspection/nodes/when_singleline.rb +0 -24
- data/lib/super_diff/rspec/object_inspection/inspectors.rb +0 -40
- data/lib/super_diff/rspec/object_inspection/inspectors/collection_including.rb +0 -28
- data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +0 -31
- data/lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb +0 -23
- data/lib/super_diff/rspec/object_inspection/inspectors/kind_of.rb +0 -23
- data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +0 -13
- data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +0 -29
- data/spec/support/object_id.rb +0 -27
- data/spec/support/ruby_versions.rb +0 -11
- data/spec/unit/object_inspection_spec.rb +0 -1168
@@ -1,23 +0,0 @@
|
|
1
|
-
module SuperDiff
|
2
|
-
module ActiveRecord
|
3
|
-
module DiffFormatters
|
4
|
-
class ActiveRecordRelation < SuperDiff::DiffFormatters::Base
|
5
|
-
def self.applies_to?(operation_tree)
|
6
|
-
operation_tree.is_a?(OperationTrees::ActiveRecordRelation)
|
7
|
-
end
|
8
|
-
|
9
|
-
def call
|
10
|
-
SuperDiff::DiffFormatters::Collection.call(
|
11
|
-
open_token: "#<ActiveRecord::Relation [",
|
12
|
-
close_token: "]>",
|
13
|
-
collection_prefix: collection_prefix,
|
14
|
-
build_item_prefix: proc { "" },
|
15
|
-
operation_tree: operation_tree,
|
16
|
-
indent_level: indent_level,
|
17
|
-
add_comma: add_comma?,
|
18
|
-
)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module SuperDiff
|
2
|
-
module ActiveRecord
|
3
|
-
module ObjectInspection
|
4
|
-
module Inspectors
|
5
|
-
autoload(
|
6
|
-
:ActiveRecordModel,
|
7
|
-
"super_diff/active_record/object_inspection/inspectors/active_record_model",
|
8
|
-
)
|
9
|
-
autoload(
|
10
|
-
:ActiveRecordRelation,
|
11
|
-
"super_diff/active_record/object_inspection/inspectors/active_record_relation",
|
12
|
-
)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module SuperDiff
|
2
|
-
module ActiveSupport
|
3
|
-
module DiffFormatters
|
4
|
-
class HashWithIndifferentAccess < SuperDiff::DiffFormatters::Base
|
5
|
-
def self.applies_to?(operation_tree)
|
6
|
-
operation_tree.is_a?(OperationTrees::HashWithIndifferentAccess)
|
7
|
-
end
|
8
|
-
|
9
|
-
def call
|
10
|
-
SuperDiff::DiffFormatters::Collection.call(
|
11
|
-
open_token: "#<HashWithIndifferentAccess {",
|
12
|
-
close_token: "}>",
|
13
|
-
collection_prefix: collection_prefix,
|
14
|
-
build_item_prefix: -> (operation) {
|
15
|
-
key =
|
16
|
-
if operation.respond_to?(:left_key)
|
17
|
-
operation.left_key
|
18
|
-
else
|
19
|
-
operation.key
|
20
|
-
end
|
21
|
-
|
22
|
-
if key.is_a?(Symbol)
|
23
|
-
"#{key}: "
|
24
|
-
else
|
25
|
-
"#{key.inspect} => "
|
26
|
-
end
|
27
|
-
},
|
28
|
-
operation_tree: operation_tree,
|
29
|
-
indent_level: indent_level,
|
30
|
-
add_comma: add_comma?,
|
31
|
-
)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
module SuperDiff
|
2
|
-
module ActiveSupport
|
3
|
-
module ObjectInspection
|
4
|
-
module Inspectors
|
5
|
-
class HashWithIndifferentAccess < SuperDiff::ObjectInspection::Inspectors::Base
|
6
|
-
def self.applies_to?(value)
|
7
|
-
value.is_a?(::HashWithIndifferentAccess)
|
8
|
-
end
|
9
|
-
|
10
|
-
protected
|
11
|
-
|
12
|
-
def inspection_tree
|
13
|
-
SuperDiff::ObjectInspection::InspectionTree.new do
|
14
|
-
add_text "#<HashWithIndifferentAccess {"
|
15
|
-
|
16
|
-
nested do |hash|
|
17
|
-
insert_hash_inspection_of(hash)
|
18
|
-
end
|
19
|
-
|
20
|
-
add_break " "
|
21
|
-
add_text "}>"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module SuperDiff
|
2
|
-
module DiffFormatters
|
3
|
-
autoload :Array, "super_diff/diff_formatters/array"
|
4
|
-
autoload :Base, "super_diff/diff_formatters/base"
|
5
|
-
autoload :Collection, "super_diff/diff_formatters/collection"
|
6
|
-
autoload :CustomObject, "super_diff/diff_formatters/custom_object"
|
7
|
-
autoload :DefaultObject, "super_diff/diff_formatters/default_object"
|
8
|
-
autoload :Hash, "super_diff/diff_formatters/hash"
|
9
|
-
autoload :Main, "super_diff/diff_formatters/main"
|
10
|
-
autoload :MultilineString, "super_diff/diff_formatters/multiline_string"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
require "super_diff/diff_formatters/defaults"
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module SuperDiff
|
2
|
-
module DiffFormatters
|
3
|
-
class Array < Base
|
4
|
-
def self.applies_to?(operation_tree)
|
5
|
-
operation_tree.is_a?(OperationTrees::Array)
|
6
|
-
end
|
7
|
-
|
8
|
-
def call
|
9
|
-
Collection.call(
|
10
|
-
open_token: "[",
|
11
|
-
close_token: "]",
|
12
|
-
collection_prefix: collection_prefix,
|
13
|
-
build_item_prefix: proc { "" },
|
14
|
-
operation_tree: operation_tree,
|
15
|
-
indent_level: indent_level,
|
16
|
-
add_comma: add_comma?,
|
17
|
-
)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module SuperDiff
|
2
|
-
module DiffFormatters
|
3
|
-
class Base
|
4
|
-
def self.applies_to?(*)
|
5
|
-
raise NotImplementedError
|
6
|
-
end
|
7
|
-
|
8
|
-
include ImplementationChecks
|
9
|
-
extend AttrExtras.mixin
|
10
|
-
|
11
|
-
method_object(
|
12
|
-
:operation_tree,
|
13
|
-
[
|
14
|
-
:indent_level!,
|
15
|
-
collection_prefix: "",
|
16
|
-
add_comma: false,
|
17
|
-
],
|
18
|
-
)
|
19
|
-
|
20
|
-
def call
|
21
|
-
raise NotImplementedError
|
22
|
-
end
|
23
|
-
|
24
|
-
# rubocop:disable Lint/UselessAccessModifier
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
# rubocop:enable Lint/UselessAccessModifier
|
29
|
-
|
30
|
-
attr_query :add_comma?
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module SuperDiff
|
2
|
-
module DiffFormatters
|
3
|
-
class CustomObject < DefaultObject
|
4
|
-
def self.applies_to?(operation_tree)
|
5
|
-
operation_tree.is_a?(OperationTrees::CustomObject)
|
6
|
-
end
|
7
|
-
|
8
|
-
def call
|
9
|
-
Collection.call(
|
10
|
-
open_token: "#<#{value_class} {",
|
11
|
-
close_token: "}>",
|
12
|
-
collection_prefix: collection_prefix,
|
13
|
-
build_item_prefix: -> (operation) {
|
14
|
-
key =
|
15
|
-
if operation.respond_to?(:left_key)
|
16
|
-
operation.left_key
|
17
|
-
else
|
18
|
-
operation.key
|
19
|
-
end
|
20
|
-
|
21
|
-
"#{key}: "
|
22
|
-
},
|
23
|
-
operation_tree: operation_tree,
|
24
|
-
indent_level: indent_level,
|
25
|
-
add_comma: add_comma?,
|
26
|
-
)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module SuperDiff
|
2
|
-
module DiffFormatters
|
3
|
-
class DefaultObject < Base
|
4
|
-
def self.applies_to?(operation_tree)
|
5
|
-
operation_tree.is_a?(OperationTrees::DefaultObject)
|
6
|
-
end
|
7
|
-
|
8
|
-
def initialize(operation_tree, value_class: nil, **rest)
|
9
|
-
super(operation_tree, **rest)
|
10
|
-
|
11
|
-
@value_class = value_class
|
12
|
-
end
|
13
|
-
|
14
|
-
def call
|
15
|
-
Collection.call(
|
16
|
-
open_token: "#<#{value_class} {",
|
17
|
-
close_token: "}>",
|
18
|
-
collection_prefix: collection_prefix,
|
19
|
-
build_item_prefix: -> (operation) {
|
20
|
-
key =
|
21
|
-
if operation.respond_to?(:left_key)
|
22
|
-
operation.left_key
|
23
|
-
else
|
24
|
-
operation.key
|
25
|
-
end
|
26
|
-
|
27
|
-
"@#{key}="
|
28
|
-
},
|
29
|
-
operation_tree: operation_tree,
|
30
|
-
indent_level: indent_level,
|
31
|
-
add_comma: add_comma?,
|
32
|
-
)
|
33
|
-
end
|
34
|
-
|
35
|
-
protected
|
36
|
-
|
37
|
-
def value_class
|
38
|
-
if @value_class
|
39
|
-
@value_class
|
40
|
-
else
|
41
|
-
unimplemented_instance_method!
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module SuperDiff
|
2
|
-
module DiffFormatters
|
3
|
-
class Hash < Base
|
4
|
-
def self.applies_to?(operation_tree)
|
5
|
-
operation_tree.is_a?(OperationTrees::Hash)
|
6
|
-
end
|
7
|
-
|
8
|
-
def call
|
9
|
-
Collection.call(
|
10
|
-
open_token: "{",
|
11
|
-
close_token: "}",
|
12
|
-
collection_prefix: collection_prefix,
|
13
|
-
build_item_prefix: -> (operation) {
|
14
|
-
key =
|
15
|
-
if operation.respond_to?(:left_key)
|
16
|
-
operation.left_key
|
17
|
-
else
|
18
|
-
operation.key
|
19
|
-
end
|
20
|
-
|
21
|
-
if key.is_a?(Symbol)
|
22
|
-
"#{key}: "
|
23
|
-
else
|
24
|
-
"#{key.inspect} => "
|
25
|
-
end
|
26
|
-
},
|
27
|
-
operation_tree: operation_tree,
|
28
|
-
indent_level: indent_level,
|
29
|
-
add_comma: add_comma?,
|
30
|
-
)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module SuperDiff
|
2
|
-
module DiffFormatters
|
3
|
-
class Main
|
4
|
-
extend AttrExtras.mixin
|
5
|
-
|
6
|
-
method_object(
|
7
|
-
:operation_tree,
|
8
|
-
[
|
9
|
-
:indent_level!,
|
10
|
-
add_comma: false,
|
11
|
-
value_class: nil,
|
12
|
-
],
|
13
|
-
)
|
14
|
-
|
15
|
-
def call
|
16
|
-
if resolved_class
|
17
|
-
resolved_class.call(
|
18
|
-
operation_tree,
|
19
|
-
indent_level: indent_level,
|
20
|
-
add_comma: add_comma?,
|
21
|
-
value_class: value_class,
|
22
|
-
)
|
23
|
-
else
|
24
|
-
raise NoDiffFormatterAvailableError.create(operation_tree)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
attr_query :add_comma?
|
31
|
-
|
32
|
-
def resolved_class
|
33
|
-
available_classes.find { |klass| klass.applies_to?(operation_tree) }
|
34
|
-
end
|
35
|
-
|
36
|
-
def available_classes
|
37
|
-
DEFAULTS + SuperDiff.configuration.extra_diff_formatter_classes
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module SuperDiff
|
2
|
-
module ObjectInspection
|
3
|
-
module Inspectors
|
4
|
-
autoload :Base, "super_diff/object_inspection/inspectors/base"
|
5
|
-
autoload :Array, "super_diff/object_inspection/inspectors/array"
|
6
|
-
autoload(
|
7
|
-
:CustomObject,
|
8
|
-
"super_diff/object_inspection/inspectors/custom_object",
|
9
|
-
)
|
10
|
-
autoload(
|
11
|
-
:DefaultObject,
|
12
|
-
"super_diff/object_inspection/inspectors/default_object",
|
13
|
-
)
|
14
|
-
autoload :Hash, "super_diff/object_inspection/inspectors/hash"
|
15
|
-
autoload :Main, "super_diff/object_inspection/inspectors/main"
|
16
|
-
autoload :Primitive, "super_diff/object_inspection/inspectors/primitive"
|
17
|
-
autoload :String, "super_diff/object_inspection/inspectors/string"
|
18
|
-
autoload :TimeLike, "super_diff/object_inspection/inspectors/time_like"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
require "super_diff/object_inspection/inspectors/defaults"
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module SuperDiff
|
2
|
-
module ObjectInspection
|
3
|
-
module Inspectors
|
4
|
-
class Array < Base
|
5
|
-
def self.applies_to?(value)
|
6
|
-
value.is_a?(::Array)
|
7
|
-
end
|
8
|
-
|
9
|
-
protected
|
10
|
-
|
11
|
-
def inspection_tree
|
12
|
-
InspectionTree.new do
|
13
|
-
when_empty do
|
14
|
-
add_text "[]"
|
15
|
-
end
|
16
|
-
|
17
|
-
when_non_empty do
|
18
|
-
add_text "["
|
19
|
-
|
20
|
-
nested do |array|
|
21
|
-
insert_array_inspection_of(array)
|
22
|
-
end
|
23
|
-
|
24
|
-
add_break
|
25
|
-
add_text "]"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module SuperDiff
|
2
|
-
module ObjectInspection
|
3
|
-
module Inspectors
|
4
|
-
class Base
|
5
|
-
extend AttrExtras.mixin
|
6
|
-
extend ImplementationChecks
|
7
|
-
|
8
|
-
def self.applies_to?(_value)
|
9
|
-
unimplemented_class_method!
|
10
|
-
end
|
11
|
-
|
12
|
-
method_object :object, [:as_single_line!, :indent_level]
|
13
|
-
|
14
|
-
def call
|
15
|
-
SuperDiff::RecursionGuard.substituting_recursion_of(object) do
|
16
|
-
inspection_tree.evaluate(
|
17
|
-
object,
|
18
|
-
as_single_line: as_single_line,
|
19
|
-
indent_level: indent_level,
|
20
|
-
)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
protected
|
25
|
-
|
26
|
-
def inspection_tree
|
27
|
-
unimplemented_instance_method!
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
attr_query :as_single_line?
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|