datacaster 5.0.1 → 6.0.1
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/README.md +7 -7
- data/lib/datacaster/array_schema.rb +1 -1
- data/lib/datacaster/predefined.rb +1 -1
- data/lib/datacaster/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0072ba53600fb794462c13dba4fe31c9134aac67e5a7687f0e91e17483cf10b1
|
4
|
+
data.tar.gz: b35c2f8b667d884bcf641be2d79747c65a68b97a7da20abc718776b3fe532af6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16903213c77a60b38d8a034ac88b39deaddf926474fcc9eeb575c7633d4742a3aab51c1a6e56b094bcbbc6dff5ae5ed5911a9c4e17bd12cc14df51f1f230e790
|
7
|
+
data.tar.gz: 5f3da501cb763c39f330cc8406bbd9a4e6db76db255612884c92fbb89a5fca0f8d8f81f72295941bc078b969bf5a3f1e2cfd1552eccda9cff30930c244398961
|
data/README.md
CHANGED
@@ -332,7 +332,7 @@ Notice that OR operator, if left-hand validation fails, passes the original valu
|
|
332
332
|
|
333
333
|
#### *IF... THEN... ELSE operator*
|
334
334
|
|
335
|
-
Let's
|
335
|
+
Let's suppose we want to run different validations depending on some value, e.g.:
|
336
336
|
|
337
337
|
* if 'salary' is more than 100_000, check for the additional key, 'passport'
|
338
338
|
* otherwise, ensure 'passport' key is absent
|
@@ -373,7 +373,7 @@ Formally, with `a.then(b).else(c)`:
|
|
373
373
|
|
374
374
|
Note: this construct is *not* an equivalent of `a & b | c`.
|
375
375
|
|
376
|
-
With `a.then(b).else(c)` if `a` and `b` fails, then `b`'s error is returned. With `a & b | c`, instead, `c`'s result would be returned.
|
376
|
+
With `a.then(b).else(c)` if `a` passes and `b` fails, then `b`'s error is returned. With `a & b | c`, instead, `c`'s result would be returned.
|
377
377
|
|
378
378
|
#### *SWITCH... ON... ELSE operator*
|
379
379
|
|
@@ -1128,13 +1128,13 @@ To define compound data type, array of 'something', use `array_schema(something)
|
|
1128
1128
|
salaries = Datacaster.schema { array_of(integer) }
|
1129
1129
|
|
1130
1130
|
salaries.([1000, 2000, 3000]) # Datacaster::ValidResult([1000, 2000, 3000])
|
1131
|
+
salaries.([]) # Datacaster::ValidResult([])
|
1131
1132
|
|
1132
1133
|
salaries.(["one thousand"]) # Datacaster::ErrorResult({0=>["is not an integer"]})
|
1133
1134
|
salaries.(:not_an_array) # Datacaster::ErrorResult(["should be an array"])
|
1134
|
-
salaries.([]) # Datacaster::ErrorResult(["should not be empty"])
|
1135
1135
|
```
|
1136
1136
|
|
1137
|
-
To
|
1137
|
+
To disallow empty array use the following construct: `array_of(..., allow_empty: false)`.
|
1138
1138
|
|
1139
1139
|
If you want to define an array of hashes, [shortcut definition](#shortcut-nested-definitions) could be used: instead of `array_of(hash_schema({...}))` use `array_of({...})`:
|
1140
1140
|
|
@@ -1371,11 +1371,11 @@ Had we used `schema` everywhere, `CommonFieldsValidator` would return failure fo
|
|
1371
1371
|
|
1372
1372
|
As a rule of thumb, use `partial_schema` in any "intermediary" validators (extracted for the sake of clarity of code and reusability) and use `schema` in any "end" validators (ones which receive full record as input and use intermediary validators behind the scenes).
|
1373
1373
|
|
1374
|
-
Lastly, if you want to just delete extra unvalidated keys without returning
|
1374
|
+
Lastly, if you want to just delete extra unvalidated keys without returning an error, use `choosy_schema`.
|
1375
1375
|
|
1376
1376
|
#### AND with error aggregation (`*`)
|
1377
1377
|
|
1378
|
-
Often it is useful to run
|
1378
|
+
Often it is useful to run validators which are "further down the conveyor" (i.e. placed at the right-hand side of AND operator `&`) even if current (i.e. left-hand side) validator has failed.
|
1379
1379
|
|
1380
1380
|
Let's say we have extracted some "common validations" and have some concrete validators, which utilize these reusable common validations (more or less repeating the motif of the previous example, shortening non-essential for this section parts for clarity):
|
1381
1381
|
|
@@ -1793,7 +1793,7 @@ All keyword arguments of `#i18n_key`, `#i18n_scope` and designed for that sole p
|
|
1793
1793
|
|
1794
1794
|
It is possible to add i18n variables at the runtime (e.g. inside `check { ... }` block) by calling `i18n_vars!(variable: 'value')` or `i18n_var!(:variable, 'value')`.
|
1795
1795
|
|
1796
|
-
Outer calls of `#i18n_key` (`#i18n_scope`, `#i18n_vars`) have
|
1796
|
+
Outer calls of `#i18n_key` (`#i18n_scope`, `#i18n_vars`) have precedence before the inner if variable names collide. However, runtime calls of `#i18n_vars!` and `#i18n_var!` overwrite compile-time variables from the next nearest key, scope or vars on collision.
|
1797
1797
|
|
1798
1798
|
## Registering custom 'predefined' types
|
1799
1799
|
|
@@ -40,7 +40,7 @@ module Datacaster
|
|
40
40
|
Trier.new(catched_exception, error_key, &block)
|
41
41
|
end
|
42
42
|
|
43
|
-
def array_schema(element_caster, error_keys = {}, allow_empty:
|
43
|
+
def array_schema(element_caster, error_keys = {}, allow_empty: true)
|
44
44
|
ArraySchema.new(DefinitionDSL.expand(element_caster), error_keys, allow_empty:)
|
45
45
|
end
|
46
46
|
alias_method :array_of, :array_schema
|
data/lib/datacaster/version.rb
CHANGED
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:
|
4
|
+
version: 6.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugene Zolotarev
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -106,7 +106,7 @@ dependencies:
|
|
106
106
|
- - "<"
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '3'
|
109
|
-
description:
|
109
|
+
description:
|
110
110
|
email:
|
111
111
|
- eugzol@gmail.com
|
112
112
|
executables: []
|
@@ -181,7 +181,7 @@ licenses:
|
|
181
181
|
- MIT
|
182
182
|
metadata:
|
183
183
|
source_code_uri: https://github.com/EugZol/datacaster
|
184
|
-
post_install_message:
|
184
|
+
post_install_message:
|
185
185
|
rdoc_options: []
|
186
186
|
require_paths:
|
187
187
|
- lib
|
@@ -196,8 +196,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
196
196
|
- !ruby/object:Gem::Version
|
197
197
|
version: '0'
|
198
198
|
requirements: []
|
199
|
-
rubygems_version: 3.
|
200
|
-
signing_key:
|
199
|
+
rubygems_version: 3.1.6
|
200
|
+
signing_key:
|
201
201
|
specification_version: 4
|
202
202
|
summary: Run-time type checker and transformer for Ruby
|
203
203
|
test_files: []
|