constrain 0.6.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/TODO +8 -2
- data/lib/constrain/version.rb +1 -1
- data/lib/constrain.rb +7 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b497524127f01a38cc3c6f4061e91e0cad65b587538d57f69b194a550d46bf1
|
4
|
+
data.tar.gz: 95cff0709eb06ab088fee635c5629de99d16f521f9d24ea0a603ddb4d0968780
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f843d4f4b653ab255f52d9c5188b3d9d72c0170e0f4af4522404e4d993b97f6629b0b61c665a9cc47f3fc89a22ca7f7beb9efd68dfdae186c5d1502b320004d7
|
7
|
+
data.tar.gz: 70654e57d920e7f13a92394d57f7b5ddff2529ebe346507de201f47ce9aad77beef17992419dea84f1ba795b4de7d8443a65d3250b9a46298f8b1896d43dbeb4
|
data/TODO
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
|
2
|
-
o
|
2
|
+
o Use | to create class-or expressions
|
3
|
+
o Old: Class | Class syntax
|
4
|
+
o Use & to construct tuple expressions
|
5
|
+
o Old: A tuple method: "Symbol => constrain.tuple(String, Integer)"
|
6
|
+
o Better error message for 'constrain EXPR'
|
7
|
+
o Explain that 'constrain EXPR' can be used for 'constrain SomeClass < AnotherClass'
|
8
|
+
o Match ranges and regular expressions
|
3
9
|
o An array and hash method: "Symbol => constrain.array(Integer), String => constrain.hash(Symbol, Integer)"
|
4
|
-
o Class | Class syntax
|
5
10
|
o Constrained attributes: constrain_reader, constrain_writer, constrain_accessor:
|
6
11
|
o Messages should include info about the unexpected element type in arrays (and maybe more): "Expected [#<PgGraph::Data::Record:public.pings[1] {id: 1, name: 'Ping A'}>, #<PgGraph::Data::Record:public.pings[2] {id: 2, name: 'Ping B'}>, nil] to match [PgGraph::Data::Record]
|
7
12
|
|
8
13
|
+ constrain value, class-expr, "Error message"
|
9
14
|
+ Check against values: 'constrain arg, :one_value, :another_value, 1, 2, 3'
|
15
|
+
+ Allow 'constrain EXRP'
|
data/lib/constrain/version.rb
CHANGED
data/lib/constrain.rb
CHANGED
@@ -65,9 +65,12 @@ module Constrain
|
|
65
65
|
end
|
66
66
|
|
67
67
|
begin
|
68
|
-
|
69
|
-
|
70
|
-
|
68
|
+
if exprs.empty?
|
69
|
+
value or raise MatchError.new(value, [], message: message, unwind: unwind)
|
70
|
+
else
|
71
|
+
exprs.any? { |expr| Constrain.do_constrain_value?(value, expr) } or
|
72
|
+
raise MatchError.new(value, exprs, message: message, unwind: unwind)
|
73
|
+
end
|
71
74
|
rescue ArgumentError, Constrain::MatchError => ex
|
72
75
|
ex.set_backtrace(caller[1 + unwind..-1])
|
73
76
|
raise
|
@@ -85,7 +88,7 @@ module Constrain
|
|
85
88
|
def self.do_constrain_value?(value, expr)
|
86
89
|
case expr
|
87
90
|
when Class, Module
|
88
|
-
value
|
91
|
+
expr === value
|
89
92
|
when Array
|
90
93
|
!expr.empty? or raise ArgumentError, "Empty array in constraint"
|
91
94
|
value.is_a?(Array) && value.all? { |elem| expr.any? { |e| Constrain.constrain?(elem, e) } }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: constrain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claus Rasmussen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simplecov
|