lab42_data_class 0.8.1 → 0.8.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7be679faed4f29c62488aceab84698e74d6d2e0fae75484e02455f5af8de2776
|
4
|
+
data.tar.gz: f8754463c2419091dfdcca58c29c2cc04a828a3b82e08ad9379ccf9a54357cd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74673122bfc71202fc07f9f193e233972516d6a1d98c0170613bb7c5288d2e318a21fb2e5c45e477e62a6c47cbdc6bc596f6c5743553f4d73fd1cf58c0af4960
|
7
|
+
data.tar.gz: 6c41a6118819b88f66422ff5ed4f72cd9d561b655cc1e2d860fee9bc6eba913571814279ea163c223009bb7cb511d3e76f43aef15b2e0cb7cef5a1c706a12fe1
|
@@ -7,8 +7,12 @@ module Lab42
|
|
7
7
|
class Constraint
|
8
8
|
attr_reader :name, :function
|
9
9
|
|
10
|
-
def call(value)
|
10
|
+
def call(value)
|
11
|
+
function.(value)
|
12
|
+
end
|
13
|
+
|
11
14
|
def setter_constraint? = false
|
15
|
+
def to_proc = function
|
12
16
|
def to_s = "Constraint<#{name}>"
|
13
17
|
|
14
18
|
private
|
@@ -5,9 +5,9 @@ module Lab42
|
|
5
5
|
module DataClass
|
6
6
|
class Proxy
|
7
7
|
module Constraints
|
8
|
-
def check_constraints_against_defaults
|
8
|
+
def check_constraints_against_defaults
|
9
9
|
errors = constraints
|
10
|
-
.
|
10
|
+
.flat_map(&_check_constraint_against_default)
|
11
11
|
.compact
|
12
12
|
raise ConstraintError, errors.join("\n\n") unless errors.empty?
|
13
13
|
end
|
@@ -19,7 +19,7 @@ module Lab42
|
|
19
19
|
"constraints cannot be defined for undefined attributes #{errors.inspect}"
|
20
20
|
end
|
21
21
|
|
22
|
-
check_constraints_against_defaults
|
22
|
+
check_constraints_against_defaults
|
23
23
|
end
|
24
24
|
|
25
25
|
private
|
@@ -32,9 +32,11 @@ module Lab42
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
def _check_constraint_against_default_value(attr, value,
|
36
|
-
|
37
|
-
|
35
|
+
def _check_constraint_against_default_value(attr, value, constraints)
|
36
|
+
constraints.map do |constraint|
|
37
|
+
unless constraint.(value)
|
38
|
+
"default value #{value.inspect} is not allowed for attribute #{attr.inspect}"
|
39
|
+
end
|
38
40
|
end
|
39
41
|
rescue StandardError => e
|
40
42
|
"constraint error during validation of default value of attribute #{attr.inspect}\n #{e.message}"
|