lab42_basic_constraints 0.1.4 → 0.1.5
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 -0
- data/lib/lab42/basic_constraints/constraint.rb +13 -6
- data/lib/lab42/basic_constraints/version.rb +1 -1
- 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: 565e1a087c775182c1acd5da145eb753d5af7c3e9cd1dd15d14faa85f4d19c87
|
4
|
+
data.tar.gz: 839aae5929011f9e088db5fdaf869dc050bfcc85ec8286450e97ea6bcd75975f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9185a0999ba47fc278888cd04c02426a4cd02c897221d75a59abdca5166bbfa6ecfa7bf2439b95eb7af6cf0367b13713578f786fc5e40c65795306fa00d7392
|
7
|
+
data.tar.gz: 6097207f6d78749e7ef8f6a229f6a6a1ecdd1cf6608416bebbf3061acd193f4f06464e822f8e910692828da1cf364f463c5c91a725251d5a4a334de2ed25dce0
|
data/README.md
CHANGED
@@ -75,6 +75,11 @@ Example: Constraints with and without defaults
|
|
75
75
|
|
76
76
|
```
|
77
77
|
|
78
|
+
Example: Avoiding the Exception, à la `Hash#fetch`
|
79
|
+
```ruby
|
80
|
+
expect( BC.from_symbol(:positive_number).default{42} ).to eq(42)
|
81
|
+
```
|
82
|
+
|
78
83
|
A detailed description of all constraints can be found
|
79
84
|
[here](speculations/constraints.md)
|
80
85
|
|
@@ -12,12 +12,17 @@ module Lab42
|
|
12
12
|
Result.error("#{_show value} is not a legal #{@name}", error: Lab42::BasicConstraints::ConstraintError)
|
13
13
|
end
|
14
14
|
|
15
|
-
def default
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
def default &blk
|
16
|
+
if @has_default
|
17
|
+
case @default
|
18
|
+
when Proc
|
19
|
+
@default.()
|
20
|
+
else
|
21
|
+
@default
|
22
|
+
end
|
19
23
|
else
|
20
|
-
|
24
|
+
return blk.() if blk
|
25
|
+
raise Lab42::BasicConstraints::MissingDefaultError, "Constraint #{name} has no predefined default"
|
21
26
|
end
|
22
27
|
end
|
23
28
|
|
@@ -28,6 +33,7 @@ module Lab42
|
|
28
33
|
else
|
29
34
|
blk
|
30
35
|
end
|
36
|
+
@has_default = true
|
31
37
|
self
|
32
38
|
end
|
33
39
|
|
@@ -43,7 +49,8 @@ module Lab42
|
|
43
49
|
|
44
50
|
def initialize name, &blk
|
45
51
|
@constraint = blk
|
46
|
-
@
|
52
|
+
@has_default = false
|
53
|
+
@default = -> {}
|
47
54
|
@name = name
|
48
55
|
end
|
49
56
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lab42_basic_constraints
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lab42_result
|