datacaster 3.3.1 → 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/datacaster/hash_mapper.rb +3 -2
- data/lib/datacaster/predefined.rb +4 -3
- data/lib/datacaster/runtimes/structure_cleaner.rb +5 -0
- data/lib/datacaster/transformer.rb +5 -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: 9709949f8f91c24538332b215d2d08af58a7b1e83869dcde0198512889b1775c
|
4
|
+
data.tar.gz: 791d875d336e229796f302b448256b6b4ad1a3d6f10e10702af49a3cbb6faf4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7631f63485017a7c431993b80ecb9795c060e02c8742a2cf82400866b578e244caa9d2e783769cf7b3d153336d8242790c68daf652c6d53fdbe94f387230a1bc
|
7
|
+
data.tar.gz: 551810cf2025496263579b9b3bfd051970a5149a08bf51fd6ac7a4b6ad40fc74b8819fb3e941e7738a8e2e826f75ac5119759864ea740826e95ca3c30d9e316a
|
data/README.md
CHANGED
@@ -849,7 +849,7 @@ I18n keys:
|
|
849
849
|
|
850
850
|
#### `transform_to_value(value)`
|
851
851
|
|
852
|
-
Always returns ValidResult. The value is transformed to provided argument (disregarding the original value).
|
852
|
+
Always returns ValidResult. The value is transformed to provided argument (disregarding the original value). If the resultant value is a Hash, all its keys are marked as validated and will survive `Datacaster.schema { ... }` call.
|
853
853
|
|
854
854
|
Returned value is deeply frozen with [`Ractor::make_shareable`](https://docs.ruby-lang.org/en/master/Ractor.html#method-c-make_shareable) to prevent application bugs due to modification of unintentionally shared value. If that effect is undesired, use [`transform { value }`](#transform--value--) instead.
|
855
855
|
|
@@ -1070,6 +1070,8 @@ Useful to perform some side-effect such as raising an exception, making a log en
|
|
1070
1070
|
|
1071
1071
|
Always returns ValidResult. Transforms the value: returns whatever the block has returned.
|
1072
1072
|
|
1073
|
+
If the resultant value is a Hash, all its keys are marked as validated and will survive `Datacaster.schema { ... }` call.
|
1074
|
+
|
1073
1075
|
```ruby
|
1074
1076
|
city =
|
1075
1077
|
Datacaster.schema do
|
@@ -1087,6 +1089,8 @@ city.(name: "Denver", distance: "2.5") # => Datacaster::ValidResult({:name=>"Den
|
|
1087
1089
|
|
1088
1090
|
Always returns ValidResult. If the value is `Datacaster.absent`, then `Datacaster.absent` is returned (the block isn't called). Otherwise, works like [`transform`](#transform--value).
|
1089
1091
|
|
1092
|
+
If the resultant value is a Hash, all its keys are marked as validated and will survive `Datacaster.schema { ... }` call.
|
1093
|
+
|
1090
1094
|
### Array schemas
|
1091
1095
|
|
1092
1096
|
To define compound data type, array of 'something', use `array_schema(something)` (or the alias `array_of(something)`). There is no built-in way to define an array wherein each element is of a different type.
|
@@ -17,8 +17,6 @@ module Datacaster
|
|
17
17
|
errors = {}
|
18
18
|
result = {}
|
19
19
|
|
20
|
-
runtime.will_check!
|
21
|
-
|
22
20
|
@fields.each do |key, validator|
|
23
21
|
new_value = runtime.ignore_checks! { validator.with_runtime(runtime).(object) }
|
24
22
|
|
@@ -52,6 +50,9 @@ module Datacaster
|
|
52
50
|
end
|
53
51
|
end
|
54
52
|
|
53
|
+
runtime.will_check!
|
54
|
+
result.keys.each { |key| runtime.checked_key!(key) }
|
55
|
+
|
55
56
|
errors.delete_if { |_, v| v.empty? }
|
56
57
|
|
57
58
|
if errors.empty?
|
@@ -161,7 +161,7 @@ module Datacaster
|
|
161
161
|
end
|
162
162
|
|
163
163
|
def pass
|
164
|
-
|
164
|
+
cast { |v| Datacaster::ValidResult(v) }
|
165
165
|
end
|
166
166
|
|
167
167
|
def pass_if(base)
|
@@ -189,7 +189,7 @@ module Datacaster
|
|
189
189
|
end
|
190
190
|
end
|
191
191
|
|
192
|
-
must_be(Enumerable) &
|
192
|
+
must_be(Enumerable) & cast { |input|
|
193
193
|
result =
|
194
194
|
keys.map do |key|
|
195
195
|
Array(key).reduce(input) do |result, k|
|
@@ -198,7 +198,8 @@ module Datacaster
|
|
198
198
|
result
|
199
199
|
end
|
200
200
|
end
|
201
|
-
keys.length == 1 ? result.first : result
|
201
|
+
result = keys.length == 1 ? result.first : result
|
202
|
+
Datacaster::ValidResult(result)
|
202
203
|
}
|
203
204
|
end
|
204
205
|
|
@@ -32,9 +32,14 @@ module Datacaster
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def will_check!
|
35
|
+
return if @ignore
|
35
36
|
@should_check_stack[-1] = true
|
36
37
|
end
|
37
38
|
|
39
|
+
def will_not_check!
|
40
|
+
@should_check_stack[-1] = false
|
41
|
+
end
|
42
|
+
|
38
43
|
# Notify current runtime that some child runtime has built schema,
|
39
44
|
# child runtime's schema is passed as the argument
|
40
45
|
def checked_schema!(schema)
|
@@ -7,7 +7,11 @@ module Datacaster
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def cast(object, runtime:)
|
10
|
-
|
10
|
+
result = Runtimes::Base.(runtime, @transform, object)
|
11
|
+
if runtime.respond_to?(:will_not_check!)
|
12
|
+
runtime.will_not_check!
|
13
|
+
end
|
14
|
+
Datacaster::ValidResult(result)
|
11
15
|
end
|
12
16
|
|
13
17
|
def inspect
|
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: 4.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: 2024-
|
11
|
+
date: 2024-10-08 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: []
|
@@ -178,7 +178,7 @@ licenses:
|
|
178
178
|
- MIT
|
179
179
|
metadata:
|
180
180
|
source_code_uri: https://github.com/EugZol/datacaster
|
181
|
-
post_install_message:
|
181
|
+
post_install_message:
|
182
182
|
rdoc_options: []
|
183
183
|
require_paths:
|
184
184
|
- lib
|
@@ -193,8 +193,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
195
|
requirements: []
|
196
|
-
rubygems_version: 3.5.
|
197
|
-
signing_key:
|
196
|
+
rubygems_version: 3.5.21
|
197
|
+
signing_key:
|
198
198
|
specification_version: 4
|
199
199
|
summary: Run-time type checker and transformer for Ruby
|
200
200
|
test_files: []
|