datacaster 3.2.6 → 3.2.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c44e05c449320297096373bd48d942aae81776c5ad358f831215d875628d0ce2
4
- data.tar.gz: 831752e1d0028d3d9e3d9423e515c34b587d13aecdcd24be4b12a1d74d073b61
3
+ metadata.gz: 7e5f8dec00cd9987c6efe8bbf54939b6a4df8604cffb7bc2be43d3e97fc8c8b7
4
+ data.tar.gz: a2bf2ab038537307304aade93ec9143fe489ece282ffb6d1bb92cdbe0d241de9
5
5
  SHA512:
6
- metadata.gz: eb18dda544b94751ed2d389e3191d9372f0e9323a162c489fc10731da26cc643d2151ff55a600152dea496d1831251b24bfc00ebf294b13b22a2954f64173cae
7
- data.tar.gz: ae9c906810ff03d978b5b85c07a6042750ad92ed46dbe7ea55318a3a1a61ab85ba2854482de5d9c34aa234aed1c687730d1ff4ee80b8232a8a42a28daeecdfa0
6
+ metadata.gz: 4a99eaac0cfdb79b651ea7056dd77e279768e0ad0123107fb26f211cfe5d0bd605b0bfd19b649ac6041ac8a527c1314b5202ba790c2dfbea5bd85363a06756a6
7
+ data.tar.gz: d351457a3693f7a919fe0252cfc664973231c91c7b50dd2404beb4bfefa4d515541147272bafbf9fd53b109e6565f04fd4202adaa9fa347587422f0342b08be4
data/README.md CHANGED
@@ -31,6 +31,8 @@ It is currently used in production in several projects (mainly as request parame
31
31
  - [`hash_with_symbolized_keys(error_key = nil)`](#hash_with_symbolized_keyserror_key--nil)
32
32
  - [`integer32(error_key = nil)`](#integer32error_key--nil)
33
33
  - [`non_empty_string(error_key = nil)`](#non_empty_stringerror_key--nil)
34
+ - [`pattern(regexp, error_key = nil)`](#patternregexp-error_key--nil)
35
+ - [`uuid(error_key = nil)`](#uuiderror_key--nil)
34
36
  - [Special types](#special-types)
35
37
  - [`absent(error_key = nil, on: nil)`](#absenterror_key--nil-on-nil)
36
38
  - [`any(error_key = nil)`](#anyerror_key--nil)
@@ -525,9 +527,29 @@ I18n keys:
525
527
 
526
528
  Returns ValidResult if and only if provided value is a string and is not empty. Doesn't transform the value.
527
529
 
530
+ I18n keys:
531
+
528
532
  * not a string – `error_key`, `'.string'`, `'datacaster.errors.string'`
529
533
  * is empty – `error_key`, `'.non_empty_string'`, `'datacaster.errors.non_empty_string'`
530
534
 
535
+ #### `pattern(regexp, error_key = nil)`
536
+
537
+ Returns ValidResult if and only if provided value is a string and satisfies regexp. Doesn't transform the value. Don't forget to provide start/end markers in the regexp if needed, e.g. `/\A\d+\z/` for digits-only string.
538
+
539
+ I18n keys:
540
+
541
+ * not a string – `error_key`, `'.string'`, `'datacaster.errors.string'`
542
+ * doesn't satisfy the regexp – `error_key`, `'.pattern'`, `'datacaster.errors.pattern'`
543
+
544
+ #### `uuid(error_key = nil)`
545
+
546
+ Returns ValidResult if and only if provided value is a string and UUID. Doesn't transform the value.
547
+
548
+ I18n keys:
549
+
550
+ * not a string – `error_key`, `'.string'`, `'datacaster.errors.string'`
551
+ * not UUID – `error_key`, `'.uuid'`, `'datacaster.errors.uuid'`
552
+
531
553
  ### Special types
532
554
 
533
555
  #### `absent(error_key = nil, on: nil)`
@@ -1327,7 +1349,7 @@ CommonValidator =
1327
1349
  end
1328
1350
 
1329
1351
  PersonValidator =
1330
- Datacaster.schema do
1352
+ Datacaster.partial_schema do
1331
1353
  hash_schema(
1332
1354
  name: string
1333
1355
  )
@@ -16,6 +16,7 @@ en:
16
16
  integer32: is not a 32-bit integer
17
17
  iso8601: is not a string with ISO-8601 date and time
18
18
  must_be: "is not %{reference}"
19
+ pattern: has invalid format
19
20
  relate: "%{left} should be %{op} %{right}"
20
21
  responds_to: "does not respond to %{reference}"
21
22
  string: is not a string
@@ -25,3 +26,4 @@ en:
25
26
  non_empty_string: should be non-empty string
26
27
  switch: is invalid
27
28
  try: raised an error
29
+ uuid: is not UUID
@@ -24,10 +24,15 @@ module Datacaster
24
24
  def transform_result(result)
25
25
  return result unless result.valid?
26
26
  result = cast_success(result)
27
- parent_runtime = @runtime.instance_variable_get(:@parent)
28
- if parent_runtime.respond_to?(:checked_schema!)
29
- parent_runtime.checked_schema!(@runtime.checked_schema)
27
+
28
+ # Notify parent runtime of current runtime's schema
29
+ unless @runtime.unchecked?
30
+ parent_runtime = @runtime.instance_variable_get(:@parent)
31
+ if parent_runtime.respond_to?(:checked_schema!)
32
+ parent_runtime.checked_schema!(@runtime.checked_schema)
33
+ end
30
34
  end
35
+
31
36
  result
32
37
  end
33
38
 
@@ -319,6 +319,12 @@ module Datacaster
319
319
  check { |x| x.is_a?(Float) }.i18n_key(*error_keys)
320
320
  end
321
321
 
322
+ def pattern(regexp, error_key = nil)
323
+ error_keys = ['.pattern', 'datacaster.errors.pattern']
324
+ error_keys.unshift(error_key) if error_key
325
+ string(error_key) & check { |x| x.match?(regexp) }.i18n_key(*error_keys, reference: regexp.inspect)
326
+ end
327
+
322
328
  # 'hash' would be a bad method name, because it would override built in Object#hash
323
329
  def hash_value(error_key = nil)
324
330
  error_keys = ['.hash_value', 'datacaster.errors.hash_value']
@@ -360,6 +366,12 @@ module Datacaster
360
366
  string(error_key) & check { |x| !x.empty? }.i18n_key(*error_keys)
361
367
  end
362
368
 
369
+ def uuid(error_key = nil)
370
+ error_keys = ['.uuid', 'datacaster.errors.uuid']
371
+ error_keys.unshift(error_key) if error_key
372
+ string(error_key) & pattern(/\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/).i18n_key(*error_keys)
373
+ end
374
+
363
375
  # Form request types
364
376
 
365
377
  def iso8601(error_key = nil)
@@ -47,6 +47,7 @@ module Datacaster
47
47
  @pointer_stack[-1] = true
48
48
  # Child runtime's schema should be merged with current runtime's schema
49
49
  else
50
+ will_check!
50
51
  @pointer_stack[-1].merge!(schema)
51
52
  end
52
53
  end
@@ -1,3 +1,3 @@
1
1
  module Datacaster
2
- VERSION = "3.2.6"
2
+ VERSION = "3.2.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datacaster
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.6
4
+ version: 3.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugene Zolotarev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-13 00:00:00.000000000 Z
11
+ date: 2024-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel