evt-schema 2.5.0.0.pre.1 → 2.5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/schema/controls/schema.rb +10 -8
- data/lib/schema/schema.rb +29 -20
- data/lib/schema.rb +1 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7f39ba650c62ee4bf0f2de29183ab17eb1425d770f56d098584d744d6d6cb02
|
4
|
+
data.tar.gz: d0474a2e4d66b03ef4424a06fab9ecb0683570ff55bdd928895717cd238fd59f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fb7c6d8ca133bd24cb212430e488a8dfbdf2e794cfc35addb7a186e1b1e9febbeaf70bfed375153fd8dda5cc216d6fc6f53f4135e2a1504da29c73a835e2383
|
7
|
+
data.tar.gz: dfd3e8e2e47d6dfbe0f064926f9b6fac9b26cfa0ece8956f1ecb5dda7fe6cf4dc1a1b45dadacea386c95adbef2b29edb63f392afd916eb4eee9c1d1adb84859e
|
@@ -138,13 +138,7 @@ module Schema
|
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
|
-
module
|
142
|
-
def self.check
|
143
|
-
lambda do |type, value|
|
144
|
-
value == Check.valid_some_attribute
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
141
|
+
module TypeCheck
|
148
142
|
def self.valid_some_attribute
|
149
143
|
"some-valid-value"
|
150
144
|
end
|
@@ -153,9 +147,17 @@ module Schema
|
|
153
147
|
"some-invalid-value"
|
154
148
|
end
|
155
149
|
|
150
|
+
class ExampleType
|
151
|
+
module TypeCheck
|
152
|
+
def self.call(type, value)
|
153
|
+
value == Schema::TypeCheck.valid_some_attribute
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
156
158
|
class Example
|
157
159
|
include ::Schema
|
158
|
-
attribute :some_attribute,
|
160
|
+
attribute :some_attribute, ExampleType
|
159
161
|
end
|
160
162
|
end
|
161
163
|
|
data/lib/schema/schema.rb
CHANGED
@@ -25,12 +25,12 @@ module Schema
|
|
25
25
|
end
|
26
26
|
|
27
27
|
module AttributeMacro
|
28
|
-
def attribute_macro(attribute_name, type=nil, default: nil
|
29
|
-
|
28
|
+
def attribute_macro(attribute_name, type=nil, default: nil)
|
29
|
+
type_check = TypeCheck.get(type)
|
30
30
|
|
31
|
-
|
32
|
-
if not
|
33
|
-
raise Schema::Attribute::TypeError, "#{val.inspect} of type #{val.class.name} cannot be assigned to attribute #{attribute_name.inspect} of #{
|
31
|
+
check = lambda do |val|
|
32
|
+
if not type_check.(type, val)
|
33
|
+
raise Schema::Attribute::TypeError, "#{val.inspect} of type #{val.class.name} cannot be assigned to #{self.to_s} attribute #{attribute_name.inspect} of type #{type.name}"
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -42,25 +42,30 @@ module Schema
|
|
42
42
|
raise Schema::Attribute::Error, "Default values must be callable, like procs, lambdas, or objects that respond to the call method (Attribute: #{attribute_name})"
|
43
43
|
end
|
44
44
|
|
45
|
-
::Attribute::Define.(self, attribute_name, :accessor, check:
|
45
|
+
::Attribute::Define.(self, attribute_name, :accessor, check: check, &initialize_value)
|
46
46
|
|
47
47
|
attribute = attributes.register(attribute_name, type)
|
48
48
|
attribute
|
49
49
|
end
|
50
50
|
alias :attribute :attribute_macro
|
51
51
|
|
52
|
-
module
|
53
|
-
def self.
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
52
|
+
module TypeCheck
|
53
|
+
def self.call(type, val)
|
54
|
+
return true if val.nil?
|
55
|
+
return true if type.nil?
|
56
|
+
|
57
|
+
val.is_a?(type)
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.get(type)
|
61
|
+
return self if type.nil?
|
62
|
+
|
63
|
+
result = Reflect.(type, :TypeCheck, ancestors: true, strict: false)
|
64
|
+
|
65
|
+
if not result.nil?
|
66
|
+
return result.constant
|
67
|
+
else
|
68
|
+
return self
|
64
69
|
end
|
65
70
|
end
|
66
71
|
end
|
@@ -148,8 +153,12 @@ module Schema
|
|
148
153
|
end
|
149
154
|
|
150
155
|
module Boolean
|
151
|
-
|
152
|
-
|
156
|
+
module TypeCheck
|
157
|
+
def self.call(type, val)
|
158
|
+
return true if val.nil?
|
159
|
+
|
160
|
+
val == true || val == false
|
161
|
+
end
|
153
162
|
end
|
154
163
|
end
|
155
164
|
|
data/lib/schema.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evt-schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.5.0.0
|
4
|
+
version: 2.5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Eventide Project
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: evt-attribute
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: evt-reflect
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: test_bench
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
151
|
- !ruby/object:Gem::Version
|
138
152
|
version: '0'
|
139
153
|
requirements: []
|
140
|
-
rubygems_version: 3.5.
|
154
|
+
rubygems_version: 3.5.22
|
141
155
|
signing_key:
|
142
156
|
specification_version: 4
|
143
157
|
summary: Primitives for schema and data structure
|