lab42_data_class 0.8.0 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/lab42/data_class/constraints/constraint.rb +5 -1
- data/lib/lab42/data_class/proxy/constraints/maker.rb +1 -1
- data/lib/lab42/data_class/proxy/constraints.rb +8 -6
- data/lib/lab42/data_class/proxy.rb +1 -1
- data/lib/lab42/data_class/version.rb +1 -1
- data/lib/lab42/list.rb +26 -9
- data/lib/lab42/nil.rb +19 -4
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5eeca60436c025c569f2b33678f4a52da196c909d8292de9fe1e1226aac9567
|
4
|
+
data.tar.gz: cd593944b7fb98dc0150ec2876a70c25f4afc23bb0afe0dffc1af437e81f1fdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99a0f3bb88fc1f6cdcd67292da3822cb62f911d8e8970cf481db8389d1ec5751e556356c66616f68989842748a84069c913db8420a4bc97521188016036b5947
|
7
|
+
data.tar.gz: 1ccda21d84aea6275132aa86f50cc8ed98415dc79f806f4abe5736b73ab6e6604d861120644072e089ba8810243018e2c9de61a594e2b0fbeed6cb302c7a8afb
|
@@ -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}"
|
data/lib/lab42/list.rb
CHANGED
@@ -7,27 +7,44 @@ module Lab42
|
|
7
7
|
include Enumerable
|
8
8
|
attr_reader :car, :cdr, :length
|
9
9
|
|
10
|
-
def ==(other)
|
10
|
+
def ==(other)
|
11
11
|
self.class.list?(other) &&
|
12
12
|
length == other.length &&
|
13
13
|
car == other.car &&
|
14
14
|
cdr == other.cdr
|
15
|
+
end
|
15
16
|
|
16
|
-
def cadr
|
17
|
+
def cadr
|
18
|
+
cdr.car
|
19
|
+
end
|
17
20
|
|
18
|
-
def caddr
|
21
|
+
def caddr
|
22
|
+
cdr.cdr.car
|
23
|
+
end
|
19
24
|
|
20
|
-
def cddr
|
25
|
+
def cddr
|
26
|
+
cdr.cdr
|
27
|
+
end
|
21
28
|
|
22
|
-
def cdddr
|
29
|
+
def cdddr
|
30
|
+
cdr.cdr.cdr
|
31
|
+
end
|
23
32
|
|
24
|
-
def cons(new_head)
|
33
|
+
def cons(new_head)
|
34
|
+
self.class.cons(new_head, self)
|
35
|
+
end
|
25
36
|
|
26
|
-
def deconstruct
|
37
|
+
def deconstruct
|
38
|
+
[car, cdr]
|
39
|
+
end
|
27
40
|
|
28
|
-
def each(&blk)
|
41
|
+
def each(&blk)
|
42
|
+
self.class.each(self, &blk)
|
43
|
+
end
|
29
44
|
|
30
|
-
def empty?
|
45
|
+
def empty?
|
46
|
+
false
|
47
|
+
end
|
31
48
|
end
|
32
49
|
end
|
33
50
|
# SPDX-License-Identifier: Apache-2.0
|
data/lib/lab42/nil.rb
CHANGED
@@ -4,10 +4,25 @@ module Lab42
|
|
4
4
|
module Nil
|
5
5
|
extend self, Enumerable
|
6
6
|
|
7
|
-
def deconstruct
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
def deconstruct
|
8
|
+
[]
|
9
|
+
end
|
10
|
+
|
11
|
+
def each
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def empty?
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def length
|
20
|
+
0
|
21
|
+
end
|
22
|
+
|
23
|
+
def cons(new_head)
|
24
|
+
List.cons(new_head, self)
|
25
|
+
end
|
11
26
|
end
|
12
27
|
end
|
13
28
|
# SPDX-License-Identifier: Apache-2.0
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lab42_data_class
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
An Immutable DataClass for Ruby
|
@@ -59,7 +59,7 @@ homepage: https://github.com/robertdober/lab42_data_class
|
|
59
59
|
licenses:
|
60
60
|
- Apache-2.0
|
61
61
|
metadata: {}
|
62
|
-
post_install_message:
|
62
|
+
post_install_message:
|
63
63
|
rdoc_options: []
|
64
64
|
require_paths:
|
65
65
|
- lib
|
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
version: '0'
|
76
76
|
requirements: []
|
77
77
|
rubygems_version: 3.3.3
|
78
|
-
signing_key:
|
78
|
+
signing_key:
|
79
79
|
specification_version: 4
|
80
80
|
summary: Finally a dataclass in ruby
|
81
81
|
test_files: []
|