super_diff 0.4.0 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +104 -73
- data/lib/super_diff.rb +20 -11
- data/lib/super_diff/active_record.rb +20 -24
- data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +3 -3
- data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -5
- data/lib/super_diff/active_record/object_inspection/inspectors/active_record_model.rb +32 -22
- data/lib/super_diff/active_record/object_inspection/inspectors/active_record_relation.rb +17 -7
- data/lib/super_diff/active_record/operation_tree_builders.rb +14 -0
- data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_model.rb +2 -2
- data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_relation.rb +4 -4
- data/lib/super_diff/active_record/{operation_sequences.rb → operation_trees.rb} +2 -2
- data/lib/super_diff/active_record/{operation_sequences → operation_trees}/active_record_relation.rb +2 -2
- data/lib/super_diff/active_support.rb +16 -19
- data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +3 -3
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -5
- data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +17 -7
- data/lib/super_diff/active_support/operation_tree_builders.rb +10 -0
- data/lib/super_diff/active_support/{operational_sequencers → operation_tree_builders}/hash_with_indifferent_access.rb +2 -2
- data/lib/super_diff/active_support/{operation_sequences.rb → operation_trees.rb} +2 -2
- data/lib/super_diff/active_support/{operation_sequences → operation_trees}/hash_with_indifferent_access.rb +2 -2
- data/lib/super_diff/configuration.rb +60 -0
- data/lib/super_diff/diff_formatters.rb +3 -3
- data/lib/super_diff/diff_formatters/array.rb +3 -3
- data/lib/super_diff/diff_formatters/base.rb +3 -2
- data/lib/super_diff/diff_formatters/collection.rb +2 -2
- data/lib/super_diff/diff_formatters/custom_object.rb +3 -3
- data/lib/super_diff/diff_formatters/default_object.rb +6 -8
- data/lib/super_diff/diff_formatters/defaults.rb +10 -0
- data/lib/super_diff/diff_formatters/hash.rb +3 -3
- data/lib/super_diff/diff_formatters/main.rb +41 -0
- data/lib/super_diff/diff_formatters/multiline_string.rb +3 -3
- data/lib/super_diff/differs.rb +4 -11
- data/lib/super_diff/differs/array.rb +2 -11
- data/lib/super_diff/differs/base.rb +20 -3
- data/lib/super_diff/differs/custom_object.rb +2 -11
- data/lib/super_diff/differs/default_object.rb +2 -8
- data/lib/super_diff/differs/defaults.rb +12 -0
- data/lib/super_diff/differs/hash.rb +2 -11
- data/lib/super_diff/differs/main.rb +48 -0
- data/lib/super_diff/differs/multiline_string.rb +2 -14
- data/lib/super_diff/differs/time_like.rb +15 -0
- data/lib/super_diff/equality_matchers.rb +3 -9
- data/lib/super_diff/equality_matchers/array.rb +1 -7
- data/lib/super_diff/equality_matchers/base.rb +1 -1
- data/lib/super_diff/equality_matchers/default.rb +1 -7
- data/lib/super_diff/equality_matchers/defaults.rb +12 -0
- data/lib/super_diff/equality_matchers/hash.rb +1 -7
- data/lib/super_diff/equality_matchers/main.rb +21 -0
- data/lib/super_diff/equality_matchers/multiline_string.rb +1 -7
- data/lib/super_diff/errors.rb +16 -0
- data/lib/super_diff/errors/no_diff_formatter_available_error.rb +21 -0
- data/lib/super_diff/errors/no_differ_available_error.rb +24 -0
- data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +22 -0
- data/lib/super_diff/implementation_checks.rb +19 -0
- data/lib/super_diff/object_inspection.rb +1 -10
- data/lib/super_diff/object_inspection/inspection_tree.rb +6 -2
- data/lib/super_diff/object_inspection/inspectors.rb +5 -1
- data/lib/super_diff/object_inspection/inspectors/array.rb +20 -10
- data/lib/super_diff/object_inspection/inspectors/base.rb +36 -0
- data/lib/super_diff/object_inspection/inspectors/custom_object.rb +24 -14
- data/lib/super_diff/object_inspection/inspectors/default_object.rb +44 -30
- data/lib/super_diff/object_inspection/inspectors/defaults.rb +15 -0
- data/lib/super_diff/object_inspection/inspectors/hash.rb +20 -10
- data/lib/super_diff/object_inspection/inspectors/main.rb +35 -0
- data/lib/super_diff/object_inspection/inspectors/primitive.rb +20 -5
- data/lib/super_diff/object_inspection/inspectors/string.rb +15 -5
- data/lib/super_diff/object_inspection/inspectors/time_like.rb +23 -0
- data/lib/super_diff/object_inspection/nodes/inspection.rb +9 -2
- data/lib/super_diff/operation_tree_builders.rb +18 -0
- data/lib/super_diff/{operational_sequencers → operation_tree_builders}/array.rb +38 -59
- data/lib/super_diff/operation_tree_builders/base.rb +98 -0
- data/lib/super_diff/{operational_sequencers → operation_tree_builders}/custom_object.rb +3 -3
- data/lib/super_diff/{operational_sequencers → operation_tree_builders}/default_object.rb +8 -3
- data/lib/super_diff/operation_tree_builders/defaults.rb +5 -0
- data/lib/super_diff/operation_tree_builders/hash.rb +226 -0
- data/lib/super_diff/operation_tree_builders/main.rb +42 -0
- data/lib/super_diff/{operational_sequencers → operation_tree_builders}/multiline_string.rb +3 -3
- data/lib/super_diff/operation_tree_builders/time_like.rb +34 -0
- data/lib/super_diff/operation_trees.rb +13 -0
- data/lib/super_diff/{operation_sequences → operation_trees}/array.rb +5 -1
- data/lib/super_diff/{operation_sequences → operation_trees}/base.rb +9 -1
- data/lib/super_diff/{operation_sequences → operation_trees}/custom_object.rb +5 -1
- data/lib/super_diff/{operation_sequences → operation_trees}/default_object.rb +10 -8
- data/lib/super_diff/operation_trees/defaults.rb +5 -0
- data/lib/super_diff/{operation_sequences → operation_trees}/hash.rb +5 -1
- data/lib/super_diff/operation_trees/main.rb +35 -0
- data/lib/super_diff/operation_trees/multiline_string.rb +18 -0
- data/lib/super_diff/operations/unary_operation.rb +3 -0
- data/lib/super_diff/recursion_guard.rb +2 -0
- data/lib/super_diff/rspec.rb +45 -13
- data/lib/super_diff/rspec/augmented_matcher.rb +1 -1
- data/lib/super_diff/rspec/differ.rb +2 -17
- data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +2 -7
- data/lib/super_diff/rspec/differs/collection_including.rb +2 -7
- data/lib/super_diff/rspec/differs/hash_including.rb +2 -7
- data/lib/super_diff/rspec/differs/object_having_attributes.rb +2 -7
- data/lib/super_diff/rspec/matcher_text_builders/match.rb +1 -1
- data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +1 -1
- data/lib/super_diff/rspec/matcher_text_template.rb +1 -1
- data/lib/super_diff/rspec/monkey_patches.rb +9 -5
- data/lib/super_diff/rspec/object_inspection.rb +0 -1
- data/lib/super_diff/rspec/object_inspection/inspectors.rb +16 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/collection_containing_exactly.rb +17 -8
- data/lib/super_diff/rspec/object_inspection/inspectors/collection_including.rb +15 -9
- data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +20 -10
- data/lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb +23 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/kind_of.rb +23 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/object_having_attributes.rb +20 -11
- data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +13 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +29 -0
- data/lib/super_diff/rspec/operation_tree_builders.rb +22 -0
- data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/collection_containing_exactly.rb +5 -5
- data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/collection_including.rb +2 -2
- data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/hash_including.rb +3 -11
- data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/object_having_attributes.rb +4 -8
- data/lib/super_diff/version.rb +1 -1
- data/spec/examples.txt +5 -0
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +354 -227
- data/spec/integration/rspec/include_matcher_spec.rb +2 -2
- data/spec/integration/rspec/unhandled_errors_spec.rb +81 -4
- data/spec/support/command_runner.rb +3 -0
- data/spec/support/integration/helpers.rb +12 -96
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +14 -29
- data/spec/support/integration/test_programs/base.rb +120 -0
- data/spec/support/integration/test_programs/plain.rb +13 -0
- data/spec/support/integration/test_programs/rspec_active_record.rb +17 -0
- data/spec/support/integration/test_programs/rspec_rails.rb +17 -0
- data/spec/support/models/active_record/person.rb +4 -11
- data/spec/support/models/active_record/shipping_address.rb +10 -14
- data/spec/support/object_id.rb +6 -5
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +724 -208
- data/spec/unit/{equality_matcher_spec.rb → equality_matchers/main_spec.rb} +157 -1
- data/spec/unit/object_inspection_spec.rb +77 -1
- data/spec/unit/rspec/matchers/raise_error_spec.rb +16 -0
- data/super_diff.gemspec +4 -5
- metadata +77 -56
- data/lib/super_diff/active_record/object_inspection/map_extension.rb +0 -18
- data/lib/super_diff/active_record/operational_sequencers.rb +0 -14
- data/lib/super_diff/active_support/object_inspection/map_extension.rb +0 -15
- data/lib/super_diff/active_support/operational_sequencers.rb +0 -10
- data/lib/super_diff/diff_formatter.rb +0 -32
- data/lib/super_diff/differ.rb +0 -51
- data/lib/super_diff/differs/time.rb +0 -24
- data/lib/super_diff/equality_matcher.rb +0 -32
- data/lib/super_diff/no_differ_available_error.rb +0 -22
- data/lib/super_diff/no_operational_sequencer_available_error.rb +0 -20
- data/lib/super_diff/object_inspection/inspector.rb +0 -27
- data/lib/super_diff/object_inspection/inspectors/time.rb +0 -13
- data/lib/super_diff/object_inspection/map.rb +0 -30
- data/lib/super_diff/operation_sequences.rb +0 -9
- data/lib/super_diff/operational_sequencer.rb +0 -48
- data/lib/super_diff/operational_sequencers.rb +0 -17
- data/lib/super_diff/operational_sequencers/base.rb +0 -89
- data/lib/super_diff/operational_sequencers/hash.rb +0 -85
- data/lib/super_diff/operational_sequencers/time_like.rb +0 -30
- data/lib/super_diff/rspec/configuration.rb +0 -31
- data/lib/super_diff/rspec/object_inspection/map_extension.rb +0 -23
- data/lib/super_diff/rspec/operational_sequencers.rb +0 -22
@@ -0,0 +1,21 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module EqualityMatchers
|
3
|
+
class Main
|
4
|
+
extend AttrExtras.mixin
|
5
|
+
|
6
|
+
method_object [:expected!, :actual!, extra_classes: []]
|
7
|
+
|
8
|
+
def call
|
9
|
+
resolved_class.call(expected: expected, actual: actual)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def resolved_class
|
15
|
+
(DEFAULTS + extra_classes).find do |klass|
|
16
|
+
klass.applies_to?(expected) && klass.applies_to?(actual)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -34,13 +34,7 @@ module SuperDiff
|
|
34
34
|
private
|
35
35
|
|
36
36
|
def diff
|
37
|
-
Differs::MultilineString.call(
|
38
|
-
expected,
|
39
|
-
actual,
|
40
|
-
indent_level: 0,
|
41
|
-
extra_operational_sequencer_classes: extra_operational_sequencer_classes,
|
42
|
-
extra_diff_formatter_classes: extra_diff_formatter_classes,
|
43
|
-
)
|
37
|
+
Differs::MultilineString.call(expected, actual, indent_level: 0)
|
44
38
|
end
|
45
39
|
end
|
46
40
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Errors
|
3
|
+
autoload(
|
4
|
+
:NoDiffFormatterAvailableError,
|
5
|
+
"super_diff/errors/no_diff_formatter_available_error",
|
6
|
+
)
|
7
|
+
autoload(
|
8
|
+
:NoDifferAvailableError,
|
9
|
+
"super_diff/errors/no_differ_available_error",
|
10
|
+
)
|
11
|
+
autoload(
|
12
|
+
:NoOperationTreeBuilderAvailableError,
|
13
|
+
"super_diff/errors/no_operation_tree_builder_available_error",
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Errors
|
3
|
+
class NoDiffFormatterAvailableError < StandardError
|
4
|
+
def self.create(operation_tree)
|
5
|
+
allocate.tap do |error|
|
6
|
+
error.operation_tree = operation_tree
|
7
|
+
error.__send__(:initialize)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_accessor :operation_tree
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
super(<<-MESSAGE)
|
15
|
+
There is no diff formatter available to handle an operation tree object of
|
16
|
+
#{operation_tree.class}.
|
17
|
+
MESSAGE
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Errors
|
3
|
+
class NoDifferAvailableError < 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 differ 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
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Errors
|
3
|
+
class NoOperationalSequencerAvailableError < 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 operational sequencer available to handle an "expected" value of
|
17
|
+
type #{expected.class} and an "actual" value of type #{actual.class}.
|
18
|
+
MESSAGE
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
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
|
@@ -1,24 +1,15 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module ObjectInspection
|
3
3
|
autoload :InspectionTree, "super_diff/object_inspection/inspection_tree"
|
4
|
-
autoload :Inspector, "super_diff/object_inspection/inspector"
|
5
4
|
autoload :Inspectors, "super_diff/object_inspection/inspectors"
|
6
|
-
autoload :Map, "super_diff/object_inspection/map"
|
7
5
|
autoload :Nodes, "super_diff/object_inspection/nodes"
|
8
6
|
|
9
|
-
class << self
|
10
|
-
attr_accessor :map
|
11
|
-
end
|
12
|
-
|
13
7
|
def self.inspect(object, as_single_line:, indent_level: 0)
|
14
|
-
|
15
|
-
map,
|
8
|
+
Inspectors::Main.call(
|
16
9
|
object,
|
17
10
|
as_single_line: as_single_line,
|
18
11
|
indent_level: indent_level,
|
19
12
|
)
|
20
13
|
end
|
21
|
-
|
22
|
-
self.map = Map.new
|
23
14
|
end
|
24
15
|
end
|
@@ -107,8 +107,12 @@ module SuperDiff
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
|
-
def add_inspection_of(value)
|
111
|
-
|
110
|
+
def add_inspection_of(value = nil, &block)
|
111
|
+
if block
|
112
|
+
add_node :inspection, &block
|
113
|
+
else
|
114
|
+
add_node :inspection, value
|
115
|
+
end
|
112
116
|
end
|
113
117
|
|
114
118
|
def apply_tree(tree)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module ObjectInspection
|
3
3
|
module Inspectors
|
4
|
+
autoload :Base, "super_diff/object_inspection/inspectors/base"
|
4
5
|
autoload :Array, "super_diff/object_inspection/inspectors/array"
|
5
6
|
autoload(
|
6
7
|
:CustomObject,
|
@@ -11,9 +12,12 @@ module SuperDiff
|
|
11
12
|
"super_diff/object_inspection/inspectors/default_object",
|
12
13
|
)
|
13
14
|
autoload :Hash, "super_diff/object_inspection/inspectors/hash"
|
15
|
+
autoload :Main, "super_diff/object_inspection/inspectors/main"
|
14
16
|
autoload :Primitive, "super_diff/object_inspection/inspectors/primitive"
|
15
17
|
autoload :String, "super_diff/object_inspection/inspectors/string"
|
16
|
-
autoload :
|
18
|
+
autoload :TimeLike, "super_diff/object_inspection/inspectors/time_like"
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
22
|
+
|
23
|
+
require "super_diff/object_inspection/inspectors/defaults"
|
@@ -1,20 +1,30 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module ObjectInspection
|
3
3
|
module Inspectors
|
4
|
-
Array
|
5
|
-
|
6
|
-
|
4
|
+
class Array < Base
|
5
|
+
def self.applies_to?(value)
|
6
|
+
value.is_a?(::Array)
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
add_text "["
|
9
|
+
protected
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
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 "["
|
15
19
|
|
16
|
-
|
17
|
-
|
20
|
+
nested do |array|
|
21
|
+
insert_array_inspection_of(array)
|
22
|
+
end
|
23
|
+
|
24
|
+
add_break
|
25
|
+
add_text "]"
|
26
|
+
end
|
27
|
+
end
|
18
28
|
end
|
19
29
|
end
|
20
30
|
end
|
@@ -0,0 +1,36 @@
|
|
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
|
@@ -1,26 +1,36 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module ObjectInspection
|
3
3
|
module Inspectors
|
4
|
-
CustomObject
|
5
|
-
|
6
|
-
|
4
|
+
class CustomObject < Base
|
5
|
+
def self.applies_to?(value)
|
6
|
+
value.respond_to?(:attributes_for_super_diff)
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
add_text " {"
|
11
|
-
end
|
9
|
+
protected
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
def inspection_tree
|
12
|
+
InspectionTree.new do
|
13
|
+
add_text do |object|
|
14
|
+
"#<#{object.class}"
|
15
|
+
end
|
16
16
|
|
17
|
-
|
17
|
+
when_multiline do
|
18
|
+
add_text " {"
|
19
|
+
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
nested do |object|
|
22
|
+
insert_hash_inspection_of(object.attributes_for_super_diff)
|
23
|
+
end
|
22
24
|
|
23
|
-
|
25
|
+
add_break
|
26
|
+
|
27
|
+
when_multiline do
|
28
|
+
add_text "}"
|
29
|
+
end
|
30
|
+
|
31
|
+
add_text ">"
|
32
|
+
end
|
33
|
+
end
|
24
34
|
end
|
25
35
|
end
|
26
36
|
end
|
@@ -1,45 +1,59 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module ObjectInspection
|
3
3
|
module Inspectors
|
4
|
-
DefaultObject
|
5
|
-
|
6
|
-
|
7
|
-
object.inspect
|
8
|
-
end
|
4
|
+
class DefaultObject < Base
|
5
|
+
def self.applies_to?(_value)
|
6
|
+
true
|
9
7
|
end
|
10
8
|
|
11
|
-
|
12
|
-
when_singleline do
|
13
|
-
add_text do |object|
|
14
|
-
object.inspect
|
15
|
-
end
|
16
|
-
end
|
9
|
+
protected
|
17
10
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
11
|
+
def inspection_tree
|
12
|
+
# rubocop:disable Metrics/BlockLength
|
13
|
+
InspectionTree.new do
|
14
|
+
when_empty do
|
15
|
+
# rubocop:disable Style/SymbolProc
|
16
|
+
add_text do |object|
|
17
|
+
object.inspect
|
18
|
+
end
|
19
|
+
# rubocop:enable Style/SymbolProc
|
24
20
|
end
|
25
21
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
separator: ","
|
32
|
-
) do |name|
|
33
|
-
add_text name.to_s
|
34
|
-
add_text "="
|
35
|
-
add_inspection_of object.instance_variable_get(name)
|
22
|
+
when_non_empty do
|
23
|
+
when_singleline do
|
24
|
+
add_text do |object|
|
25
|
+
object.inspect
|
26
|
+
end
|
36
27
|
end
|
37
|
-
end
|
38
28
|
|
39
|
-
|
29
|
+
when_multiline do
|
30
|
+
add_text do |object|
|
31
|
+
"#<%<class>s:0x%<id>x {" % {
|
32
|
+
class: object.class,
|
33
|
+
id: object.object_id * 2,
|
34
|
+
}
|
35
|
+
end
|
40
36
|
|
41
|
-
|
37
|
+
nested do |object|
|
38
|
+
add_break " "
|
39
|
+
|
40
|
+
insert_separated_list(
|
41
|
+
object.instance_variables.sort,
|
42
|
+
separator: ","
|
43
|
+
) do |name|
|
44
|
+
add_text name.to_s
|
45
|
+
add_text "="
|
46
|
+
add_inspection_of object.instance_variable_get(name)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
add_break
|
51
|
+
|
52
|
+
add_text "}>"
|
53
|
+
end
|
54
|
+
end
|
42
55
|
end
|
56
|
+
# rubocop:enable Metrics/BlockLength
|
43
57
|
end
|
44
58
|
end
|
45
59
|
end
|