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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c80defc851cfda5e74a5590da7be40388643084c1e06818639685bfe05e8a46
4
- data.tar.gz: fe1a9a3b8be29b8e148917ed19052ae2d0195218624b0bf195421cc29c83c20b
3
+ metadata.gz: 9c5a664d82f1f1d267e0e45d5e259f6443e23f19d2d53aafdeca8a908984d6fe
4
+ data.tar.gz: 9296b3b4c859c7e07d96991dbaaaaf48ae005ac9c4c09d9be9353b85f668f33b
5
5
  SHA512:
6
- metadata.gz: 0b70a2c80630b51d789327c36e9b288aa2484d2b80cc888f5e8a94acf6bed1d7eef67c659f7ac17a9e7ed6c14aacc8cad9c18414881b2cfe07bf4e96aaad785e
7
- data.tar.gz: 2cde0b422e2ae297517680f2408201b3f7c88e2e1f81da667d2c875dfddd31b544bef57864dff3ac8739be01b09676e5fd22ff1cbb54677e64f791ff606d3a05
6
+ metadata.gz: f5e0293242c66c30aa1f093d78427183263e9be492577e081a8daa810e16250827401c7ee81e1764dcade73fd7934932430595f14ea9aecb5bf67219d2422124
7
+ data.tar.gz: 4bbe14148472e8c49d0af0a6b7eaf2ee3acd7f29ec26af23fd6f2fd23181ce5510886773a835474d0e53102d9c360702a3a5de90311ccb38bb552e0982055ced
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- check_please (0.5.5)
4
+ check_please (0.5.6)
5
5
  table_print
6
6
 
7
7
  GEM
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
@@ -177,4 +177,9 @@ module CheckPlease
177
177
  EOF
178
178
  end
179
179
 
180
+ Flags.define :normalize_values do |flag|
181
+ # NOTE: This flag is only accessible via the Ruby API.
182
+ # See the README for documentation.
183
+ end
184
+
180
185
  end
@@ -210,14 +210,36 @@ module CheckPlease
210
210
  end
211
211
 
212
212
  def compare_others(ref, can, path)
213
- if flags.indifferent_values
214
- ref = stringify_symbol(ref)
215
- can = stringify_symbol(can)
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
@@ -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.5" # about to release? rerun `bundle lock` to update Gemfile.lock
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.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-02-11 00:00:00.000000000 Z
11
+ date: 2021-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: table_print