validator_fn 0.3.9 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +4 -1
- data/lib/validator_fn/error.rb +1 -1
- data/lib/validator_fn/version.rb +1 -1
- data/lib/validator_fn.rb +4 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ae4f194cce16e854dccde3dc29e7d382084289945402ded960414d94dc7630f
|
4
|
+
data.tar.gz: 7a19354da9723c01d81d79540a358dad546a2611b7893399ea38b09025d83f0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 452a5fa550d3c5c9948099e1c9e2e840dd800bed22a0b8b777a81c824cdc04d0ea11f496d601fb61b750542585e96741f55292c5bbdf078e499f73b15a961c5b
|
7
|
+
data.tar.gz: c2d9d6f854407f958024efe80095490ff7d1c890ee4421f02fc5e26ee44a766c26c3e496bc996fecbe1ec4140f97e3e9a9465df6ef14faf69035ba3a1ab569dd
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -62,7 +62,7 @@ user = hash_of.({name: is_a.(String), age: to_int})
|
|
62
62
|
user.({name: "", age: "234"})
|
63
63
|
```
|
64
64
|
|
65
|
-
Since we are using curried lambdas, you can compose validators as you
|
65
|
+
Since we are using curried lambdas, you can compose validators as you wish.
|
66
66
|
|
67
67
|
```ruby
|
68
68
|
postal_code = -> a {
|
@@ -109,6 +109,9 @@ code = ValidatorFn.generate_validator.(struct)
|
|
109
109
|
# You can reformat it using a code formatter
|
110
110
|
require "rufo"
|
111
111
|
puts Rufo.format(code)
|
112
|
+
```
|
113
|
+
The output
|
114
|
+
```
|
112
115
|
hash_of.({ "login" => is_a.(String),
|
113
116
|
"id" => is_a.(Integer),
|
114
117
|
"node_id" => is_a.(String),
|
data/lib/validator_fn/error.rb
CHANGED
data/lib/validator_fn/version.rb
CHANGED
data/lib/validator_fn.rb
CHANGED
@@ -42,10 +42,13 @@ module ValidatorFn
|
|
42
42
|
@@hash_of = ->fields, hash {
|
43
43
|
hash ||= {}
|
44
44
|
fields.reduce({}) do |memo, (key, fn)|
|
45
|
-
|
45
|
+
value = hash.fetch(key) { raise MissingKey.new(key) }
|
46
|
+
memo[key] = fn.(value)
|
46
47
|
memo
|
47
48
|
rescue Error => e
|
48
49
|
invalid.("Invalid value for #{key.inspect} key:")
|
50
|
+
rescue MissingKey => e
|
51
|
+
invalid.(e.message)
|
49
52
|
end
|
50
53
|
}.curry
|
51
54
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validator_fn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Chabot
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fn_reader
|
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
requirements: []
|
70
|
-
rubygems_version: 3.4.
|
70
|
+
rubygems_version: 3.4.12
|
71
71
|
signing_key:
|
72
72
|
specification_version: 4
|
73
73
|
summary: Series of lambdas for validating Ruby structures
|