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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0e209179b85f6f4ca1b63face9260b3d8c03e7c09796e124c4606e9f8ff0431
4
- data.tar.gz: 15b4b5228319b5ff7d670dfd8f23883e714b1017ccc85dc0a3df920a142a0627
3
+ metadata.gz: 0072ba53600fb794462c13dba4fe31c9134aac67e5a7687f0e91e17483cf10b1
4
+ data.tar.gz: b35c2f8b667d884bcf641be2d79747c65a68b97a7da20abc718776b3fe532af6
5
5
  SHA512:
6
- metadata.gz: 966d31dc9b9b397ced3bece4e3a74f0c885e5b95dfebe3a35374a85c50afb4bd183222e56095730fbca3c52b079a277f8f43106c14d69192f95032d771a67a18
7
- data.tar.gz: 12043768c2e341338af7f1178aca2dead9ffd43c8189f4a2df44ca1114768aaa8fbc465e3d23c4a8e2a41162c8f73c35d789b091e18cbe67e1b5afe90214f2bc
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 support we want to run different validations depending on some value, e.g.:
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 allow empty array use the following construct: `compare([]) | array_of(...)`.
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 a error, use `choosy_schema`.
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 validator 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.
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 presedence 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.
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
 
@@ -1,6 +1,6 @@
1
1
  module Datacaster
2
2
  class ArraySchema < Base
3
- def initialize(element_caster, error_keys = {}, allow_empty: false)
3
+ def initialize(element_caster, error_keys = {}, allow_empty: true)
4
4
  @element_caster = element_caster
5
5
  @allow_empty = allow_empty
6
6
 
@@ -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: false)
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
@@ -1,3 +1,3 @@
1
1
  module Datacaster
2
- VERSION = "5.0.1"
2
+ VERSION = "6.0.1"
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: 5.0.1
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-06-05 00:00:00.000000000 Z
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.5.20
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: []