mismatch-inspectable 0.1.2 → 0.1.4
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.
- checksums.yaml +4 -4
- data/lib/mismatch_inspectable/{array_formatter.rb → formatter/array_formatter.rb} +5 -2
- data/lib/mismatch_inspectable/formatter/format_builder.rb +22 -0
- data/lib/mismatch_inspectable/formatter/formatter.rb +23 -0
- data/lib/mismatch_inspectable/{hash_formatter.rb → formatter/hash_formatter.rb} +5 -2
- data/lib/mismatch_inspectable/{object_formatter.rb → formatter/object_formatter.rb} +4 -2
- data/lib/mismatch_inspectable/inspection_options.rb +38 -0
- data/lib/mismatch_inspectable/mismatch_inspectable.rb +40 -41
- data/lib/mismatch_inspectable/version.rb +1 -1
- data/spec/examples.txt +22 -22
- metadata +11 -8
- /data/lib/mismatch_inspectable/{deep_merge.rb → formatter/deep_merge.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1183239193cb375fb2b4f262b50eae8e5a9c340274e4723ac58ee78f05f5888f
|
4
|
+
data.tar.gz: 86652b1652380b7d712442d7d4f7007f51767206e0f3d784c1ce7cff8277f41a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32129ffe106c2a2ca2b560d1a8d11230f7c7d3564cc99942583ce6b571d8bdffee763a84f790c916156aae74fd46d412f39334915a7e5ecb98a5f3c98ee4fc39
|
7
|
+
data.tar.gz: 5ec76f9a6d31017dca66125cdfe0c82b6fd65270a1bf6fb636b30c8316e3fca6be863118dc14c3cd9d259c18399680a73f6f9abe791087f91e4d612ebdcf823c
|
@@ -1,8 +1,11 @@
|
|
1
|
+
require_relative "formatter"
|
2
|
+
|
1
3
|
module MismatchInspectable
|
2
|
-
class ArrayFormatter
|
4
|
+
class ArrayFormatter < Formatter
|
3
5
|
attr_reader :mismatches
|
4
6
|
|
5
7
|
def initialize
|
8
|
+
super
|
6
9
|
@mismatches = []
|
7
10
|
end
|
8
11
|
|
@@ -10,7 +13,7 @@ module MismatchInspectable
|
|
10
13
|
@mismatches << [prefix + attribute.to_s, curr_val, other_val]
|
11
14
|
end
|
12
15
|
|
13
|
-
def
|
16
|
+
def process_mismatches(nested_mismatches)
|
14
17
|
@mismatches.concat(nested_mismatches)
|
15
18
|
end
|
16
19
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative "hash_formatter"
|
2
|
+
require_relative "array_formatter"
|
3
|
+
require_relative "object_formatter"
|
4
|
+
|
5
|
+
module MismatchInspectable
|
6
|
+
FormatBuilder = Struct.new(:format) do
|
7
|
+
def formatter
|
8
|
+
@formatter ||= select_formatter
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def select_formatter
|
14
|
+
case format
|
15
|
+
when :hash then HashFormatter.new
|
16
|
+
when :array then ArrayFormatter.new
|
17
|
+
when :object then ObjectFormatter.new
|
18
|
+
else raise ArgumentError, "Invalid format: #{format}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module MismatchInspectable
|
2
|
+
class Formatter
|
3
|
+
attr_reader :mismatches
|
4
|
+
|
5
|
+
def add_mismatch(prefix, attribute, curr_val, other_val)
|
6
|
+
raise NotImplementedError
|
7
|
+
end
|
8
|
+
|
9
|
+
def merge_mismatches(nested_mismatches)
|
10
|
+
process_mismatches(nested_mismatches) unless no_nested_mismatches?(nested_mismatches)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def no_nested_mismatches?(mismatches)
|
16
|
+
mismatches.nil? || mismatches.empty?
|
17
|
+
end
|
18
|
+
|
19
|
+
def process_mismatches(_nested_mismatches)
|
20
|
+
raise NotImplementedError
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,8 +1,11 @@
|
|
1
|
+
require_relative "formatter"
|
2
|
+
|
1
3
|
module MismatchInspectable
|
2
|
-
class HashFormatter
|
4
|
+
class HashFormatter < Formatter
|
3
5
|
attr_reader :mismatches
|
4
6
|
|
5
7
|
def initialize
|
8
|
+
super
|
6
9
|
@mismatches = Hash.new { |hash, key| hash[key] = {} }
|
7
10
|
end
|
8
11
|
|
@@ -10,7 +13,7 @@ module MismatchInspectable
|
|
10
13
|
@mismatches[prefix + attribute.to_s] = [curr_val, other_val]
|
11
14
|
end
|
12
15
|
|
13
|
-
def
|
16
|
+
def process_mismatches(nested_mismatches)
|
14
17
|
nested_mismatches.each { |k, v| mismatches[k] = v }
|
15
18
|
end
|
16
19
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
require_relative "deep_merge"
|
2
|
+
require_relative "formatter"
|
2
3
|
|
3
|
-
class ObjectFormatter
|
4
|
+
class ObjectFormatter < MismatchInspectable::Formatter
|
4
5
|
def initialize
|
6
|
+
super
|
5
7
|
@mismatches = {}.extend(DeepMerge)
|
6
8
|
end
|
7
9
|
|
@@ -19,7 +21,7 @@ class ObjectFormatter
|
|
19
21
|
curr[attribute] = [curr_val, other_val]
|
20
22
|
end
|
21
23
|
|
22
|
-
def
|
24
|
+
def process_mismatches(nested_mismatches)
|
23
25
|
mismatches.deep_merge!(nested_mismatches)
|
24
26
|
end
|
25
27
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative "formatter/format_builder"
|
2
|
+
|
3
|
+
module MismatchInspectable
|
4
|
+
class InspectionOptions
|
5
|
+
attr_accessor :recursive, :include_class, :prefix, :format, :options
|
6
|
+
|
7
|
+
def initialize(prefix: "", recursive: false, include_class: true, format: :array)
|
8
|
+
@recursive = recursive
|
9
|
+
@include_class = include_class
|
10
|
+
@prefix = prefix
|
11
|
+
@format = format
|
12
|
+
end
|
13
|
+
|
14
|
+
def formatter
|
15
|
+
@formatter ||= FormatBuilder.new(format).formatter
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_h
|
19
|
+
{
|
20
|
+
recursive:,
|
21
|
+
include_class:,
|
22
|
+
prefix:,
|
23
|
+
format:
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def update_prefix(target_class)
|
28
|
+
if include_class && comparable_prefix != "#{target_class.class}#"
|
29
|
+
self.prefix = "#{prefix}#{target_class.class}#"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def comparable_prefix
|
34
|
+
prefixes = prefix.split(".")
|
35
|
+
prefixes.length >= 2 ? prefixes[-1] : prefix
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require_relative "
|
2
|
-
require_relative "array_formatter"
|
3
|
-
require_relative "object_formatter"
|
1
|
+
require_relative "inspection_options"
|
4
2
|
|
5
3
|
module MismatchInspectable
|
4
|
+
attr_reader :options
|
5
|
+
|
6
6
|
def self.included(target_class)
|
7
7
|
target_class.extend ClassMethods
|
8
8
|
end
|
@@ -21,75 +21,74 @@ module MismatchInspectable
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
def inspect_mismatch(
|
25
|
-
|
24
|
+
def inspect_mismatch(other_klass, **options)
|
25
|
+
@options = InspectionOptions.new(**options)
|
26
|
+
find_mismatches(other_klass:)
|
27
|
+
end
|
26
28
|
|
27
|
-
|
29
|
+
protected
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
end
|
31
|
+
def find_mismatches(other_klass:)
|
32
|
+
return if self.class != other_klass.class
|
32
33
|
|
33
|
-
|
34
|
-
|
34
|
+
process_attributes!(other_klass:)
|
35
|
+
mismatches
|
35
36
|
end
|
36
37
|
|
37
38
|
private
|
38
39
|
|
39
|
-
def
|
40
|
-
|
41
|
-
when :hash then HashFormatter.new
|
42
|
-
when :array then ArrayFormatter.new
|
43
|
-
when :object then ObjectFormatter.new
|
44
|
-
else raise ArgumentError, "Invalid format: #{format}"
|
45
|
-
end
|
40
|
+
def compare_methods
|
41
|
+
self.class.compare_methods
|
46
42
|
end
|
47
43
|
|
48
|
-
|
49
|
-
def process_attributes(formatter, other, recursive, include_class, prefix, format)
|
44
|
+
def process_attributes!(other_klass:)
|
50
45
|
raise MissingCompareMethodsError if compare_methods.nil?
|
51
46
|
|
52
47
|
compare_methods.each do |attribute|
|
53
48
|
curr_val = __send__(attribute)
|
54
|
-
other_val =
|
49
|
+
other_val = other_klass.__send__(attribute)
|
55
50
|
|
56
|
-
if recursive && both_are_inspectable?(curr_val
|
57
|
-
process_recursive(
|
51
|
+
if options.recursive && both_are_inspectable?(curr_val:, other_val:)
|
52
|
+
process_recursive!(curr_val:, other_val:, attribute:)
|
58
53
|
elsif curr_val != other_val
|
59
|
-
|
60
|
-
|
54
|
+
|
55
|
+
update_prefix(target_class: self)
|
56
|
+
formatter.add_mismatch(options.prefix, attribute, curr_val, other_val)
|
61
57
|
end
|
62
58
|
end
|
63
59
|
end
|
64
60
|
|
65
|
-
def both_are_inspectable?(curr_val
|
61
|
+
def both_are_inspectable?(curr_val:, other_val:)
|
66
62
|
curr_val.respond_to?(:inspect_mismatch) && other_val.respond_to?(:inspect_mismatch)
|
67
63
|
end
|
68
64
|
|
69
|
-
def process_recursive(
|
65
|
+
def process_recursive!(curr_val:, other_val:, attribute:)
|
66
|
+
options.prefix = "#{options.prefix}#{attribute}."
|
67
|
+
options.recursive = true
|
70
68
|
nested_mismatches = curr_val.inspect_mismatch(
|
71
69
|
other_val,
|
72
|
-
|
73
|
-
include_class:,
|
74
|
-
prefix: "#{prefix}#{attribute}.",
|
75
|
-
format:
|
70
|
+
**options.to_h
|
76
71
|
)
|
72
|
+
merge_mismatches(nested_mismatches:)
|
73
|
+
end
|
77
74
|
|
78
|
-
|
75
|
+
def no_nested_mismatches?(mismatches)
|
76
|
+
mismatches.nil? || mismatches.empty?
|
79
77
|
end
|
80
|
-
# rubocop:enable Metrics/ParameterLists
|
81
78
|
|
82
|
-
def update_prefix(
|
83
|
-
|
84
|
-
include_class && comparable_prefix != "#{self.class}#" ? "#{prefix}#{self.class}#" : prefix
|
79
|
+
def update_prefix(target_class:)
|
80
|
+
options.update_prefix(target_class)
|
85
81
|
end
|
86
82
|
|
87
|
-
def
|
88
|
-
|
83
|
+
def formatter
|
84
|
+
options.formatter
|
85
|
+
end
|
86
|
+
|
87
|
+
def mismatches
|
88
|
+
formatter.mismatches
|
89
89
|
end
|
90
90
|
|
91
|
-
def
|
92
|
-
|
93
|
-
prefixes.length >= 2 ? prefixes[-1] : prefix
|
91
|
+
def merge_mismatches(nested_mismatches:)
|
92
|
+
formatter.merge_mismatches(nested_mismatches)
|
94
93
|
end
|
95
94
|
end
|
data/spec/examples.txt
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
example_id | status | run_time |
|
2
2
|
---------------------------------------------------------- | ------ | --------------- |
|
3
|
-
./spec/lib/mismatch_inspectable_spec.rb[1:1:1:1] | passed | 0.
|
4
|
-
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:1:1] | passed | 0.
|
5
|
-
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:1:2:1] | passed | 0.
|
6
|
-
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:1:3:1:1:1] | passed | 0.
|
7
|
-
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:1:3:1:1:2:1] | passed | 0.
|
8
|
-
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:1:3:1:2:1] | passed | 0.
|
9
|
-
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:1:3:1:2:2:1] | passed | 0.
|
10
|
-
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:1:3:2:1] | passed | 0.
|
11
|
-
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:1:1] | passed | 0.
|
12
|
-
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:2:1] | passed | 0.
|
13
|
-
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:3:1] | passed | 0.
|
14
|
-
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:4:1:1:1:1] | passed | 0.
|
15
|
-
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:4:1:1:2:1] | passed | 0.
|
16
|
-
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:4:1:1:3:1] | passed | 0.
|
17
|
-
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:4:1:2:1:1] |
|
18
|
-
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:4:1:2:2:1] |
|
19
|
-
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:4:1:2:3:1] |
|
20
|
-
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:4:2:1:1] | passed | 0.
|
21
|
-
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:4:2:2:1] | passed | 0.
|
22
|
-
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:4:2:3:1] | passed | 0.
|
23
|
-
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:4:3:1:1] | passed | 0.
|
24
|
-
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:4:3:2:1] |
|
3
|
+
./spec/lib/mismatch_inspectable_spec.rb[1:1:1:1] | passed | 0.00052 seconds |
|
4
|
+
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:1:1] | passed | 0.00024 seconds |
|
5
|
+
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:1:2:1] | passed | 0.00006 seconds |
|
6
|
+
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:1:3:1:1:1] | passed | 0.00008 seconds |
|
7
|
+
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:1:3:1:1:2:1] | passed | 0.00007 seconds |
|
8
|
+
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:1:3:1:2:1] | passed | 0.00007 seconds |
|
9
|
+
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:1:3:1:2:2:1] | passed | 0.00007 seconds |
|
10
|
+
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:1:3:2:1] | passed | 0.00006 seconds |
|
11
|
+
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:1:1] | passed | 0.00005 seconds |
|
12
|
+
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:2:1] | passed | 0.00005 seconds |
|
13
|
+
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:3:1] | passed | 0.00007 seconds |
|
14
|
+
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:4:1:1:1:1] | passed | 0.00094 seconds |
|
15
|
+
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:4:1:1:2:1] | passed | 0.00006 seconds |
|
16
|
+
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:4:1:1:3:1] | passed | 0.00091 seconds |
|
17
|
+
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:4:1:2:1:1] | failed | 0.00696 seconds |
|
18
|
+
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:4:1:2:2:1] | failed | 0.00043 seconds |
|
19
|
+
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:4:1:2:3:1] | failed | 0.00046 seconds |
|
20
|
+
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:4:2:1:1] | passed | 0.00008 seconds |
|
21
|
+
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:4:2:2:1] | passed | 0.00006 seconds |
|
22
|
+
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:4:2:3:1] | passed | 0.00008 seconds |
|
23
|
+
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:4:3:1:1] | passed | 0.00008 seconds |
|
24
|
+
./spec/lib/mismatch_inspectable_spec.rb[1:1:2:2:4:3:2:1] | failed | 0.00064 seconds |
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mismatch-inspectable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Rhodes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
A library that includes a module that can print mismatched
|
@@ -23,16 +23,19 @@ files:
|
|
23
23
|
- LICENSE.md
|
24
24
|
- README.md
|
25
25
|
- lib/mismatch_inspectable.rb
|
26
|
-
- lib/mismatch_inspectable/array_formatter.rb
|
27
|
-
- lib/mismatch_inspectable/deep_merge.rb
|
28
|
-
- lib/mismatch_inspectable/
|
26
|
+
- lib/mismatch_inspectable/formatter/array_formatter.rb
|
27
|
+
- lib/mismatch_inspectable/formatter/deep_merge.rb
|
28
|
+
- lib/mismatch_inspectable/formatter/format_builder.rb
|
29
|
+
- lib/mismatch_inspectable/formatter/formatter.rb
|
30
|
+
- lib/mismatch_inspectable/formatter/hash_formatter.rb
|
31
|
+
- lib/mismatch_inspectable/formatter/object_formatter.rb
|
32
|
+
- lib/mismatch_inspectable/inspection_options.rb
|
29
33
|
- lib/mismatch_inspectable/mismatch_inspectable.rb
|
30
|
-
- lib/mismatch_inspectable/object_formatter.rb
|
31
34
|
- lib/mismatch_inspectable/version.rb
|
32
35
|
- spec/examples.txt
|
33
36
|
- spec/lib/mismatch_inspectable_spec.rb
|
34
37
|
- spec/spec_helper.rb
|
35
|
-
homepage: https://github.com/
|
38
|
+
homepage: https://github.com/tylerCaineRhodes/mismatch-inspectable
|
36
39
|
licenses:
|
37
40
|
- MIT
|
38
41
|
metadata:
|
@@ -43,7 +46,7 @@ require_paths:
|
|
43
46
|
- lib
|
44
47
|
required_ruby_version: !ruby/object:Gem::Requirement
|
45
48
|
requirements:
|
46
|
-
- -
|
49
|
+
- - ">="
|
47
50
|
- !ruby/object:Gem::Version
|
48
51
|
version: 3.2.1
|
49
52
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
File without changes
|