evt-schema 2.5.0.0.pre.1 → 2.5.0.0.pre.2
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 +28 -19
- data/lib/schema.rb +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2da63ac381710f07d3eaf73c14935519846e1cf9f97ac4cbe27c472a8034af80
|
4
|
+
data.tar.gz: 7fa56b66b7524dda5089d1209040604f34247551d41dfc98f9497c576493114c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bae6ed63b133103a875b85cbb83a89e4f5b3d051408eb7da056bf11778ee4ecc60c2cc4732bc04fa2ecf62a2dbf289be604b6f97d8e5778c777b9d8f5c8518b9
|
7
|
+
data.tar.gz: 0c5604d671d62e5104632d6733d481a633f6f7c79bcffcd07b59eeb976ed784a1fbacff9aa0840b989c5563aad0d16082795910616f5c5b6e8a001a907f1918f
|
@@ -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,11 +25,11 @@ 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
|
31
|
+
check = lambda do |val|
|
32
|
+
if not type_check.(type, val)
|
33
33
|
raise Schema::Attribute::TypeError, "#{val.inspect} of type #{val.class.name} cannot be assigned to attribute #{attribute_name.inspect} of #{self.to_s}"
|
34
34
|
end
|
35
35
|
end
|
@@ -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.pre.
|
4
|
+
version: 2.5.0.0.pre.2
|
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-10-
|
11
|
+
date: 2024-10-11 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
|