super_diff 0.1.0 → 0.2.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 +117 -89
- data/lib/super_diff.rb +33 -47
- data/lib/super_diff/active_record.rb +41 -0
- data/lib/super_diff/active_record/diff_formatters.rb +10 -0
- data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +23 -0
- data/lib/super_diff/active_record/differs.rb +10 -0
- data/lib/super_diff/active_record/differs/active_record_relation.rb +30 -0
- data/lib/super_diff/active_record/object_inspection.rb +14 -0
- data/lib/super_diff/active_record/object_inspection/inspectors.rb +16 -0
- data/lib/super_diff/active_record/object_inspection/inspectors/active_record_model.rb +38 -0
- data/lib/super_diff/active_record/object_inspection/inspectors/active_record_relation.rb +18 -0
- data/lib/super_diff/active_record/object_inspection/map_extension.rb +18 -0
- data/lib/super_diff/active_record/operation_sequences.rb +10 -0
- data/lib/super_diff/active_record/operation_sequences/active_record_relation.rb +16 -0
- data/lib/super_diff/active_record/operational_sequencers.rb +14 -0
- data/lib/super_diff/active_record/operational_sequencers/active_record_model.rb +19 -0
- data/lib/super_diff/active_record/operational_sequencers/active_record_relation.rb +24 -0
- data/lib/super_diff/active_support.rb +33 -0
- data/lib/super_diff/active_support/diff_formatters.rb +10 -0
- data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +36 -0
- data/lib/super_diff/active_support/differs.rb +10 -0
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +36 -0
- data/lib/super_diff/active_support/object_inspection.rb +14 -0
- data/lib/super_diff/active_support/object_inspection/inspectors.rb +12 -0
- data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +18 -0
- data/lib/super_diff/active_support/object_inspection/map_extension.rb +15 -0
- data/lib/super_diff/active_support/operation_sequences.rb +10 -0
- data/lib/super_diff/active_support/operation_sequences/hash_with_indifferent_access.rb +16 -0
- data/lib/super_diff/active_support/operational_sequencers.rb +10 -0
- data/lib/super_diff/active_support/operational_sequencers/hash_with_indifferent_access.rb +21 -0
- data/lib/super_diff/colorized_document_extensions.rb +17 -0
- data/lib/super_diff/csi.rb +45 -15
- data/lib/super_diff/csi/bold_sequence.rb +9 -0
- data/lib/super_diff/csi/color.rb +62 -0
- data/lib/super_diff/csi/color_sequence_block.rb +28 -0
- data/lib/super_diff/csi/colorized_document.rb +72 -0
- data/lib/super_diff/csi/document.rb +183 -0
- data/lib/super_diff/csi/eight_bit_color.rb +72 -26
- data/lib/super_diff/csi/four_bit_color.rb +63 -29
- data/lib/super_diff/csi/twenty_four_bit_color.rb +79 -18
- data/lib/super_diff/csi/uncolorized_document.rb +29 -0
- data/lib/super_diff/diff_formatter.rb +10 -15
- data/lib/super_diff/diff_formatters.rb +10 -1
- data/lib/super_diff/diff_formatters/base.rb +12 -17
- data/lib/super_diff/diff_formatters/collection.rb +81 -50
- data/lib/super_diff/diff_formatters/{object.rb → custom_object.rb} +12 -9
- data/lib/super_diff/diff_formatters/default_object.rb +48 -0
- data/lib/super_diff/diff_formatters/multiline_string.rb +31 -0
- data/lib/super_diff/differ.rb +35 -32
- data/lib/super_diff/differs.rb +16 -1
- data/lib/super_diff/differs/array.rb +2 -2
- data/lib/super_diff/differs/base.rb +11 -21
- data/lib/super_diff/differs/custom_object.rb +26 -0
- data/lib/super_diff/differs/default_object.rb +25 -0
- data/lib/super_diff/differs/empty.rb +1 -1
- data/lib/super_diff/differs/hash.rb +2 -2
- data/lib/super_diff/differs/{multi_line_string.rb → multiline_string.rb} +6 -5
- data/lib/super_diff/equality_matcher.rb +9 -22
- data/lib/super_diff/equality_matchers.rb +19 -1
- data/lib/super_diff/equality_matchers/array.rb +6 -4
- data/lib/super_diff/equality_matchers/base.rb +8 -16
- data/lib/super_diff/equality_matchers/default.rb +60 -0
- data/lib/super_diff/equality_matchers/hash.rb +6 -4
- data/lib/super_diff/equality_matchers/{multi_line_string.rb → multiline_string.rb} +9 -6
- data/lib/super_diff/equality_matchers/primitive.rb +34 -0
- data/lib/super_diff/equality_matchers/{single_line_string.rb → singleline_string.rb} +7 -5
- data/lib/super_diff/helpers.rb +17 -81
- data/lib/super_diff/no_differ_available_error.rb +22 -0
- data/lib/super_diff/{errors.rb → no_operational_sequencer_available_error.rb} +0 -0
- data/lib/super_diff/object_inspection.rb +24 -0
- data/lib/super_diff/object_inspection/inspection_tree.rb +144 -0
- data/lib/super_diff/object_inspection/inspector.rb +27 -0
- data/lib/super_diff/object_inspection/inspectors.rb +18 -0
- data/lib/super_diff/object_inspection/inspectors/array.rb +22 -0
- data/lib/super_diff/object_inspection/inspectors/custom_object.rb +27 -0
- data/lib/super_diff/object_inspection/inspectors/default_object.rb +47 -0
- data/lib/super_diff/object_inspection/inspectors/hash.rb +22 -0
- data/lib/super_diff/object_inspection/inspectors/primitive.rb +13 -0
- data/lib/super_diff/object_inspection/inspectors/string.rb +13 -0
- data/lib/super_diff/object_inspection/map.rb +28 -0
- data/lib/super_diff/object_inspection/nodes.rb +49 -0
- data/lib/super_diff/object_inspection/nodes/base.rb +86 -0
- data/lib/super_diff/object_inspection/nodes/break.rb +15 -0
- data/lib/super_diff/object_inspection/nodes/inspection.rb +15 -0
- data/lib/super_diff/object_inspection/nodes/nesting.rb +16 -0
- data/lib/super_diff/object_inspection/nodes/text.rb +15 -0
- data/lib/super_diff/object_inspection/nodes/when_empty.rb +30 -0
- data/lib/super_diff/object_inspection/nodes/when_multiline.rb +22 -0
- data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +30 -0
- data/lib/super_diff/object_inspection/nodes/when_singleline.rb +24 -0
- data/lib/super_diff/operation_sequences.rb +9 -0
- data/lib/super_diff/operation_sequences/base.rb +1 -1
- data/lib/super_diff/operation_sequences/{object.rb → custom_object.rb} +4 -3
- data/lib/super_diff/operation_sequences/default_object.rb +25 -0
- data/lib/super_diff/operational_sequencer.rb +23 -18
- data/lib/super_diff/operational_sequencers.rb +12 -1
- data/lib/super_diff/operational_sequencers/array.rb +65 -62
- data/lib/super_diff/operational_sequencers/base.rb +18 -26
- data/lib/super_diff/operational_sequencers/custom_object.rb +35 -0
- data/lib/super_diff/operational_sequencers/{object.rb → default_object.rb} +21 -11
- data/lib/super_diff/operational_sequencers/hash.rb +8 -5
- data/lib/super_diff/operational_sequencers/{multi_line_string.rb → multiline_string.rb} +11 -6
- data/lib/super_diff/operations.rb +6 -0
- data/lib/super_diff/operations/binary_operation.rb +14 -34
- data/lib/super_diff/operations/unary_operation.rb +11 -2
- data/lib/super_diff/rails.rb +1 -0
- data/lib/super_diff/recursion_guard.rb +47 -0
- data/lib/super_diff/rspec-rails.rb +2 -0
- data/lib/super_diff/rspec.rb +52 -8
- data/lib/super_diff/rspec/augmented_matcher.rb +98 -0
- data/lib/super_diff/rspec/configuration.rb +31 -0
- data/lib/super_diff/rspec/differ.rb +60 -16
- data/lib/super_diff/rspec/differs.rb +13 -0
- data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +23 -0
- data/lib/super_diff/rspec/differs/partial_array.rb +22 -0
- data/lib/super_diff/rspec/differs/partial_hash.rb +22 -0
- data/lib/super_diff/rspec/differs/partial_object.rb +22 -0
- data/lib/super_diff/rspec/matcher_text_builders.rb +24 -0
- data/lib/super_diff/rspec/matcher_text_builders/base.rb +155 -0
- data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +78 -0
- data/lib/super_diff/rspec/matcher_text_builders/contain_exactly.rb +14 -0
- data/lib/super_diff/rspec/matcher_text_builders/match.rb +23 -0
- data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +13 -0
- data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +99 -0
- data/lib/super_diff/rspec/matcher_text_template.rb +240 -0
- data/lib/super_diff/rspec/monkey_patches.rb +601 -98
- data/lib/super_diff/rspec/object_inspection.rb +8 -0
- data/lib/super_diff/rspec/object_inspection/inspectors.rb +24 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/collection_containing_exactly.rb +19 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/partial_array.rb +22 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/partial_hash.rb +21 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/partial_object.rb +21 -0
- data/lib/super_diff/rspec/object_inspection/map_extension.rb +23 -0
- data/lib/super_diff/rspec/operational_sequencers.rb +22 -0
- data/lib/super_diff/rspec/operational_sequencers/collection_containing_exactly.rb +97 -0
- data/lib/super_diff/rspec/operational_sequencers/partial_array.rb +23 -0
- data/lib/super_diff/rspec/operational_sequencers/partial_hash.rb +32 -0
- data/lib/super_diff/rspec/operational_sequencers/partial_object.rb +64 -0
- data/lib/super_diff/version.rb +1 -1
- data/spec/examples.txt +328 -46
- data/spec/integration/rails/active_record_spec.rb +19 -0
- data/spec/integration/rails/hash_with_indifferent_access_spec.rb +19 -0
- data/spec/integration/rspec/be_falsey_matcher_spec.rb +53 -0
- data/spec/integration/rspec/be_matcher_spec.rb +565 -0
- data/spec/integration/rspec/be_nil_matcher_spec.rb +53 -0
- data/spec/integration/rspec/be_predicate_matcher_spec.rb +546 -0
- data/spec/integration/rspec/be_truthy_matcher_spec.rb +57 -0
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +368 -0
- data/spec/integration/rspec/eq_matcher_spec.rb +874 -0
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +299 -0
- data/spec/integration/rspec/include_matcher_spec.rb +350 -0
- data/spec/integration/rspec/match_matcher_spec.rb +1258 -0
- data/spec/integration/rspec/raise_error_matcher_spec.rb +350 -0
- data/spec/integration/rspec/respond_to_matcher_spec.rb +994 -0
- data/spec/integration/rspec/unhandled_errors_spec.rb +94 -0
- data/spec/spec_helper.rb +19 -4
- data/spec/support/colorizer.rb +9 -0
- data/spec/support/command_runner.rb +4 -0
- data/spec/support/integration/helpers.rb +179 -0
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +79 -41
- data/spec/support/models/a.rb +11 -0
- data/spec/support/models/active_record/person.rb +26 -0
- data/spec/support/models/active_record/shipping_address.rb +29 -0
- data/spec/support/models/customer.rb +24 -0
- data/spec/support/models/empty_class.rb +6 -0
- data/spec/support/models/item.rb +10 -0
- data/spec/support/models/order.rb +9 -0
- data/spec/support/models/person.rb +20 -0
- data/spec/support/models/player.rb +33 -0
- data/spec/support/models/shipping_address.rb +34 -0
- data/spec/support/ruby_versions.rb +7 -0
- data/spec/support/shared_examples/active_record.rb +338 -0
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +233 -0
- data/spec/unit/equality_matcher_spec.rb +579 -171
- data/spec/unit/object_inspection_spec.rb +1092 -0
- data/spec/unit/rspec/matchers/be_compared_to_spec.rb +23 -0
- data/spec/unit/rspec/matchers/be_falsey_spec.rb +9 -0
- data/spec/unit/rspec/matchers/be_nil_spec.rb +9 -0
- data/spec/unit/rspec/matchers/be_predicate_spec.rb +31 -0
- data/spec/unit/rspec/matchers/be_spec.rb +17 -0
- data/spec/unit/rspec/matchers/be_truthy_spec.rb +9 -0
- data/spec/unit/rspec/matchers/contain_exactly_spec.rb +11 -0
- data/spec/unit/rspec/matchers/eq_spec.rb +9 -0
- data/spec/unit/rspec/matchers/have_attributes_spec.rb +11 -0
- data/spec/unit/rspec/matchers/include_spec.rb +21 -0
- data/spec/unit/rspec/matchers/match_spec.rb +9 -0
- data/spec/unit/rspec/matchers/raise_error_spec.rb +29 -0
- data/spec/unit/rspec/matchers/respond_to_spec.rb +78 -0
- data/super_diff.gemspec +4 -2
- metadata +231 -34
- data/lib/super_diff/csi/color_helper.rb +0 -52
- data/lib/super_diff/csi/eight_bit_sequence.rb +0 -27
- data/lib/super_diff/csi/four_bit_sequence.rb +0 -24
- data/lib/super_diff/csi/sequence.rb +0 -22
- data/lib/super_diff/csi/twenty_four_bit_sequence.rb +0 -27
- data/lib/super_diff/diff_formatters/multi_line_string.rb +0 -31
- data/lib/super_diff/differs/object.rb +0 -68
- data/lib/super_diff/equality_matchers/object.rb +0 -18
- data/lib/super_diff/value_inspection.rb +0 -11
- data/spec/integration/rspec_spec.rb +0 -261
- data/spec/support/color_helper.rb +0 -49
- data/spec/support/person.rb +0 -23
- data/spec/support/person_diff_formatter.rb +0 -15
- data/spec/support/person_operation_sequence.rb +0 -14
- data/spec/support/person_operational_sequencer.rb +0 -19
@@ -0,0 +1,22 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ObjectInspection
|
3
|
+
module Inspectors
|
4
|
+
Hash = InspectionTree.new do
|
5
|
+
when_empty do
|
6
|
+
add_text "{}"
|
7
|
+
end
|
8
|
+
|
9
|
+
when_non_empty do
|
10
|
+
add_text "{"
|
11
|
+
|
12
|
+
nested do |hash|
|
13
|
+
insert_hash_inspection_of(hash)
|
14
|
+
end
|
15
|
+
|
16
|
+
add_break " "
|
17
|
+
add_text "}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ObjectInspection
|
3
|
+
class Map
|
4
|
+
def prepend(mod)
|
5
|
+
singleton_class.prepend(mod)
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(object)
|
9
|
+
if object.respond_to?(:attributes_for_super_diff)
|
10
|
+
Inspectors::CustomObject
|
11
|
+
else
|
12
|
+
case object
|
13
|
+
when Array
|
14
|
+
Inspectors::Array
|
15
|
+
when Hash
|
16
|
+
Inspectors::Hash
|
17
|
+
when String
|
18
|
+
Inspectors::String
|
19
|
+
when true, false, nil, Symbol, Numeric, Regexp, Class
|
20
|
+
Inspectors::Primitive
|
21
|
+
else
|
22
|
+
Inspectors::DefaultObject
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ObjectInspection
|
3
|
+
module Nodes
|
4
|
+
autoload :Base, "super_diff/object_inspection/nodes/base"
|
5
|
+
autoload :Break, "super_diff/object_inspection/nodes/break"
|
6
|
+
autoload :Inspection, "super_diff/object_inspection/nodes/inspection"
|
7
|
+
autoload :Nesting, "super_diff/object_inspection/nodes/nesting"
|
8
|
+
autoload :Text, "super_diff/object_inspection/nodes/text"
|
9
|
+
autoload(
|
10
|
+
:WhenEmpty,
|
11
|
+
"super_diff/object_inspection/nodes/when_empty",
|
12
|
+
)
|
13
|
+
autoload(
|
14
|
+
:WhenMultiline,
|
15
|
+
"super_diff/object_inspection/nodes/when_multiline",
|
16
|
+
)
|
17
|
+
autoload(
|
18
|
+
:WhenNonEmpty,
|
19
|
+
"super_diff/object_inspection/nodes/when_non_empty",
|
20
|
+
)
|
21
|
+
autoload(
|
22
|
+
:WhenSingleline,
|
23
|
+
"super_diff/object_inspection/nodes/when_singleline",
|
24
|
+
)
|
25
|
+
|
26
|
+
def self.fetch(type)
|
27
|
+
registry.fetch(type) do
|
28
|
+
raise(
|
29
|
+
KeyError,
|
30
|
+
"#{type.inspect} is not included in ObjectInspection::Nodes.registry!",
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.registry
|
36
|
+
@_registry ||= {
|
37
|
+
break: Break,
|
38
|
+
inspection: Inspection,
|
39
|
+
nesting: Nesting,
|
40
|
+
text: Text,
|
41
|
+
when_empty: WhenEmpty,
|
42
|
+
when_multiline: WhenMultiline,
|
43
|
+
when_non_empty: WhenNonEmpty,
|
44
|
+
when_singleline: WhenSingleline,
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ObjectInspection
|
3
|
+
module Nodes
|
4
|
+
class Base
|
5
|
+
def initialize(tree, *args, &block)
|
6
|
+
if !args.empty? && block
|
7
|
+
raise ArgumentError.new(
|
8
|
+
"You cannot provide both an immediate value and a lazy value. " +
|
9
|
+
"Either pass a block or a positional argument.",
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
@tree = tree
|
14
|
+
@immediate_value = args.first
|
15
|
+
@block = block
|
16
|
+
end
|
17
|
+
|
18
|
+
def clone_with(
|
19
|
+
tree: @tree,
|
20
|
+
immediate_value: @immediate_value,
|
21
|
+
block: @block
|
22
|
+
)
|
23
|
+
if block
|
24
|
+
self.class.new(tree, &block)
|
25
|
+
else
|
26
|
+
self.class.new(tree, immediate_value)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def type
|
31
|
+
self.class.name.
|
32
|
+
sub(/^(.+)::(.+?)$/, '\2').
|
33
|
+
gsub(/([a-z])([A-Z])/, '\1_\2').
|
34
|
+
downcase.
|
35
|
+
to_sym
|
36
|
+
end
|
37
|
+
|
38
|
+
# rubocop:disable Lint/UnusedMethodArgument
|
39
|
+
def evaluate(object, indent_level:, as_single_line:)
|
40
|
+
# rubocop:enable Lint/UnusedMethodArgument
|
41
|
+
raise NotImplementedError.new(
|
42
|
+
"Your node must provide an #evaluate method. " +
|
43
|
+
"(Keep in mind #evaluate may be called more than once for a node!)",
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
def pretty_print(pp)
|
48
|
+
pp.object_address_group(self) do
|
49
|
+
pp.seplist(pretty_print_variables, proc { pp.text "," }) do |name|
|
50
|
+
value = instance_variable_get(name)
|
51
|
+
pp.breakable " "
|
52
|
+
pp.group(1) do
|
53
|
+
pp.text name[1..-1].to_s
|
54
|
+
pp.text ":"
|
55
|
+
pp.breakable
|
56
|
+
pp.pp value
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
attr_reader :tree, :immediate_value, :block
|
65
|
+
|
66
|
+
def pretty_print_variables
|
67
|
+
if block
|
68
|
+
[:"@block"]
|
69
|
+
else
|
70
|
+
[:"@immediate_value"]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def evaluate_in_subtree(object, indent_level:, as_single_line:)
|
75
|
+
subtree = InspectionTree.new
|
76
|
+
subtree.evaluate_block(object, &block)
|
77
|
+
subtree.evaluate(
|
78
|
+
object,
|
79
|
+
indent_level: indent_level,
|
80
|
+
as_single_line: as_single_line,
|
81
|
+
)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ObjectInspection
|
3
|
+
module Nodes
|
4
|
+
class Break < Base
|
5
|
+
def evaluate(_object, indent_level:, as_single_line:)
|
6
|
+
if as_single_line
|
7
|
+
immediate_value.to_s
|
8
|
+
else
|
9
|
+
"\n#{" " * indent_level}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ObjectInspection
|
3
|
+
module Nodes
|
4
|
+
class Inspection < Base
|
5
|
+
def evaluate(_object, indent_level:, as_single_line:)
|
6
|
+
SuperDiff::ObjectInspection.inspect(
|
7
|
+
immediate_value,
|
8
|
+
indent_level: indent_level,
|
9
|
+
as_single_line: as_single_line,
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ObjectInspection
|
3
|
+
module Nodes
|
4
|
+
class Nesting < Base
|
5
|
+
def evaluate(object, indent_level:, as_single_line:)
|
6
|
+
evaluate_in_subtree(
|
7
|
+
object,
|
8
|
+
indent_level: indent_level + 1,
|
9
|
+
as_single_line: as_single_line,
|
10
|
+
&block
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ObjectInspection
|
3
|
+
module Nodes
|
4
|
+
class WhenEmpty < Base
|
5
|
+
def evaluate(object, indent_level:, as_single_line:)
|
6
|
+
if empty?(object)
|
7
|
+
evaluate_in_subtree(
|
8
|
+
object,
|
9
|
+
indent_level: indent_level,
|
10
|
+
as_single_line: as_single_line,
|
11
|
+
&block
|
12
|
+
)
|
13
|
+
else
|
14
|
+
""
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def empty?(object)
|
21
|
+
if object.respond_to?(:empty?)
|
22
|
+
object.empty?
|
23
|
+
else
|
24
|
+
object.instance_variables.empty?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ObjectInspection
|
3
|
+
module Nodes
|
4
|
+
class WhenMultiline < Base
|
5
|
+
def evaluate(object, indent_level:, as_single_line:)
|
6
|
+
if as_single_line
|
7
|
+
""
|
8
|
+
elsif block
|
9
|
+
evaluate_in_subtree(
|
10
|
+
object,
|
11
|
+
indent_level: indent_level,
|
12
|
+
as_single_line: as_single_line,
|
13
|
+
&block
|
14
|
+
)
|
15
|
+
else
|
16
|
+
immediate_value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ObjectInspection
|
3
|
+
module Nodes
|
4
|
+
class WhenNonEmpty < Base
|
5
|
+
def evaluate(object, indent_level:, as_single_line:)
|
6
|
+
if empty?(object)
|
7
|
+
""
|
8
|
+
else
|
9
|
+
evaluate_in_subtree(
|
10
|
+
object,
|
11
|
+
indent_level: indent_level,
|
12
|
+
as_single_line: as_single_line,
|
13
|
+
&block
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def empty?(object)
|
21
|
+
if object.respond_to?(:empty?)
|
22
|
+
object.empty?
|
23
|
+
else
|
24
|
+
object.instance_variables.empty?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ObjectInspection
|
3
|
+
module Nodes
|
4
|
+
class WhenSingleline < Base
|
5
|
+
def evaluate(object, indent_level:, as_single_line:)
|
6
|
+
if as_single_line
|
7
|
+
if immediate_value
|
8
|
+
immediate_value
|
9
|
+
else
|
10
|
+
evaluate_in_subtree(
|
11
|
+
object,
|
12
|
+
indent_level: indent_level,
|
13
|
+
as_single_line: as_single_line,
|
14
|
+
&block
|
15
|
+
)
|
16
|
+
end
|
17
|
+
else
|
18
|
+
""
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module OperationSequences
|
3
|
+
autoload :Array, "super_diff/operation_sequences/array"
|
4
|
+
autoload :Base, "super_diff/operation_sequences/base"
|
5
|
+
autoload :CustomObject, "super_diff/operation_sequences/custom_object"
|
6
|
+
autoload :DefaultObject, "super_diff/operation_sequences/default_object"
|
7
|
+
autoload :Hash, "super_diff/operation_sequences/hash"
|
8
|
+
end
|
9
|
+
end
|
@@ -2,7 +2,7 @@ module SuperDiff
|
|
2
2
|
module OperationSequences
|
3
3
|
class Base < SimpleDelegator
|
4
4
|
# rubocop:disable Lint/UnusedMethodArgument
|
5
|
-
def to_diff(indent_level:, add_comma
|
5
|
+
def to_diff(indent_level:, add_comma: false, collection_prefix: nil)
|
6
6
|
raise NotImplementedError
|
7
7
|
end
|
8
8
|
# rubocop:enable Lint/UnusedMethodArgument
|
@@ -1,12 +1,13 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module OperationSequences
|
3
|
-
class
|
4
|
-
def to_diff(indent_level:, collection_prefix
|
5
|
-
DiffFormatters::
|
3
|
+
class CustomObject < DefaultObject
|
4
|
+
def to_diff(indent_level:, add_comma: false, collection_prefix: nil)
|
5
|
+
DiffFormatters::CustomObject.call(
|
6
6
|
self,
|
7
7
|
indent_level: indent_level,
|
8
8
|
collection_prefix: collection_prefix,
|
9
9
|
add_comma: add_comma,
|
10
|
+
value_class: value_class,
|
10
11
|
)
|
11
12
|
end
|
12
13
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module OperationSequences
|
3
|
+
class DefaultObject < Base
|
4
|
+
def initialize(collection, value_class:)
|
5
|
+
super(collection)
|
6
|
+
|
7
|
+
@value_class = value_class
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_diff(indent_level:, add_comma: false, collection_prefix: nil)
|
11
|
+
DiffFormatters::DefaultObject.call(
|
12
|
+
self,
|
13
|
+
indent_level: indent_level,
|
14
|
+
collection_prefix: collection_prefix,
|
15
|
+
add_comma: add_comma,
|
16
|
+
value_class: value_class,
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :value_class
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|