validator_fn 0.2.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cecd9880750c518fcd26fd705b76ffeaf4604fb90af4bd60719ecf37a387d8ee
4
- data.tar.gz: d04d0ef810ab4ac5ea7b8914690c1995ffdf913c8ad4a40c5bfa85ce5ce8a817
3
+ metadata.gz: ee9bfac9a9c6e88cd08fc270860a60a919c2389a390fb7086e8767048542e0c7
4
+ data.tar.gz: 2168dc33c3a7bc6fba8f47f3832c744a2ec9514b0f9b752aa35fe2ce93d92c63
5
5
  SHA512:
6
- metadata.gz: 52647b99fdac1ff9dcf399b96d4b5a5becac6748270795cb47f0caa11e1735217239108450418781bf933dabdc0accf3ef3eaf7c9b8feb9fc1bd5f3deabe34d9
7
- data.tar.gz: 5c16a63c7a8f261cf8cf76af633dbc448975dd77cbe08074abf2dd8f77cca95b42baa3ce876c08d2f3186d52eee68edd1a94abea6b33440263e617364732d6a3
6
+ metadata.gz: 944e615250789bb463461c42aab479685ca1dba5e386550d1d54ae08234e1a7142d21c78680b0aab1071fdcbc89666e9ba6be8ed68674cbe3fe31d9677ef48a7
7
+ data.tar.gz: d4f6d2389ecfef0b4b0e12305097b3890b80577d57318a9b8cfa99ca7e0029f2eacb68fddfce295fb59b818a3f670ac68f0dbef955125253d9a0690bb870b61a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- validator_fn (0.1.8)
4
+ validator_fn (0.3.9)
5
5
  fn_reader
6
6
 
7
7
  GEM
@@ -1,3 +1,3 @@
1
1
  module ValidatorFn
2
- VERSION = "0.2.8"
2
+ VERSION = "0.3.9"
3
3
  end
data/lib/validator_fn.rb CHANGED
@@ -37,20 +37,15 @@ module ValidatorFn
37
37
  @@maybe = either.(is_nil)
38
38
  @@is_a = ->klass, a { invalid.("Expected type #{klass}, got #{a.inspect}") unless a.is_a?(klass); a }.curry
39
39
  @@is_a_bool = ->a { invalid.("Expected bool, got #{a.inspect}") unless a == true || a == false; a }.curry
40
+ # it validates each fields according with a specific algorithm, note that it
41
+ # will filter out fields that are not defined
40
42
  @@hash_of = ->fields, hash {
41
43
  hash ||= {}
42
44
  fields.reduce({}) do |memo, (key, fn)|
43
- value = hash.fetch(key, :missing_field)
44
- if value == :missing_field
45
- raise MissingKey.new(key)
46
- else
47
- memo[key] = fn.(hash[key]) if hash[key]
48
- end
45
+ memo[key] = fn.(hash[key])
49
46
  memo
50
- rescue MissingKey => e
51
- raise
52
47
  rescue Error => e
53
- invalid.("Invalid value for #{key.inspect} key.")
48
+ invalid.("Invalid value for #{key.inspect} key:")
54
49
  end
55
50
  }.curry
56
51
 
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.2.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Chabot
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-30 00:00:00.000000000 Z
11
+ date: 2023-01-23 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.1.2
70
+ rubygems_version: 3.4.1
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: Series of lambdas for validating Ruby structures