check_please 0.5.5 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +32 -0
- data/lib/check_please.rb +5 -0
- data/lib/check_please/comparison.rb +26 -4
- data/lib/check_please/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c5a664d82f1f1d267e0e45d5e259f6443e23f19d2d53aafdeca8a908984d6fe
|
4
|
+
data.tar.gz: 9296b3b4c859c7e07d96991dbaaaaf48ae005ac9c4c09d9be9353b85f668f33b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5e0293242c66c30aa1f093d78427183263e9be492577e081a8daa810e16250827401c7ee81e1764dcade73fd7934932430595f14ea9aecb5bf67219d2422124
|
7
|
+
data.tar.gz: 4bbe14148472e8c49d0af0a6b7eaf2ee3acd7f29ec26af23fd6f2fd23181ce5510886773a835474d0e53102d9c360702a3a5de90311ccb38bb552e0982055ced
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -22,6 +22,7 @@ structures parsed from either of those.
|
|
22
22
|
* [Repeatable Flags](#repeatable-flags)
|
23
23
|
* [Expanded Documentation for Specific Flags](#expanded-documentation-for-specific-flags)
|
24
24
|
* [Flag: match_by_key](#flag-match_by_key)
|
25
|
+
* [Flag: normalize_values](#flag-normalize_values)
|
25
26
|
* [TODO (maybe)](#todo-maybe)
|
26
27
|
* [Development](#development)
|
27
28
|
* [Contributing](#contributing)
|
@@ -420,6 +421,37 @@ the following path expression: `/authors/id=1/books/isbn=12345`
|
|
420
421
|
**This syntax is intended to be readable by humans first.** If you need to
|
421
422
|
build tooling that consumes it... well, I'm open to suggestions. :)
|
422
423
|
|
424
|
+
#### Flag: `normalize_values`
|
425
|
+
|
426
|
+
NOTE: This flag is only accessible via the Ruby API.
|
427
|
+
(I have no idea how to reasonably express it in a CLI flag.)
|
428
|
+
|
429
|
+
Before comparing values at specified paths, normalize both values using
|
430
|
+
the provided message or Proc.
|
431
|
+
|
432
|
+
To use an example from the tests, the following reference/candidate pair would
|
433
|
+
normally create three "mismatch" diffs:
|
434
|
+
|
435
|
+
```ruby
|
436
|
+
ref = { list: [ "foo", "bar", "yak" ] }
|
437
|
+
can = { list: [ :foo, :bar, :yak ] }
|
438
|
+
```
|
439
|
+
|
440
|
+
However, the values can be converted to String before comparison via any of the following:
|
441
|
+
|
442
|
+
```ruby
|
443
|
+
CheckPlease.diff(ref, can, normalize_values: { "/list/*" => ->(v) { v.to_s } })
|
444
|
+
CheckPlease.diff(ref, can, normalize_values: { "/list/*" => :to_s })
|
445
|
+
CheckPlease.diff(ref, can, normalize_values: { "/list/*" => "to_s" })
|
446
|
+
```
|
447
|
+
|
448
|
+
Note that the value of the flag is a Hash.
|
449
|
+
* Its keys must be strings representing path expressions.
|
450
|
+
* If the value associated with a given path is a lambda/proc, it will be
|
451
|
+
called with both the reference value and the candidate value.
|
452
|
+
* If the value is a String or Symbol, it will be sent as a message to
|
453
|
+
both the reference and candidate values using Object#send.
|
454
|
+
|
423
455
|
-----
|
424
456
|
|
425
457
|
# TODO (maybe)
|
data/lib/check_please.rb
CHANGED
@@ -210,14 +210,36 @@ module CheckPlease
|
|
210
210
|
end
|
211
211
|
|
212
212
|
def compare_others(ref, can, path)
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
end
|
213
|
+
ref = normalize_value(path, ref)
|
214
|
+
can = normalize_value(path, can)
|
215
|
+
|
217
216
|
return if ref == can
|
218
217
|
record_diff ref, can, path, :mismatch
|
219
218
|
end
|
220
219
|
|
220
|
+
def normalize_value(path, value)
|
221
|
+
if flags.indifferent_values
|
222
|
+
value = stringify_symbol(value)
|
223
|
+
end
|
224
|
+
|
225
|
+
if flags.normalize_values
|
226
|
+
# We assume that normalize_values is a hash of path expression strings to a proc, string, or symbol that will be used to normalize the value
|
227
|
+
_, normalizer = flags.normalize_values.detect { |path_string, a_proc|
|
228
|
+
path.match?(path_string)
|
229
|
+
}
|
230
|
+
|
231
|
+
case normalizer
|
232
|
+
when nil ; value
|
233
|
+
when Proc ; normalizer.call(value)
|
234
|
+
when String, Symbol ; value.send(normalizer)
|
235
|
+
else ; raise ArgumentError, "Not sure how to use #{normalizer.inspect} to normalize #{value.inspect}"
|
236
|
+
end
|
237
|
+
else
|
238
|
+
return value
|
239
|
+
end
|
240
|
+
|
241
|
+
end
|
242
|
+
|
221
243
|
def record_diff(ref, can, path, type)
|
222
244
|
diff = Diff.new(type, path, ref, can)
|
223
245
|
diffs << diff
|
data/lib/check_please/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module CheckPlease
|
2
2
|
# NOTE: 'check_please_rspec_matcher' depends on this,
|
3
3
|
# so try to keep them roughly in sync
|
4
|
-
VERSION = "0.5.
|
4
|
+
VERSION = "0.5.6" # about to release? rerun `bundle lock` to update Gemfile.lock
|
5
5
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: check_please
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Livingston-Gray
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: table_print
|