yarrow 0.7.4 → 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/yarrow/config.rb +5 -0
- data/lib/yarrow/schema/definitions.rb +6 -4
- data/lib/yarrow/schema/dictionary.rb +19 -0
- data/lib/yarrow/schema/entity.rb +3 -6
- data/lib/yarrow/schema/types.rb +90 -6
- data/lib/yarrow/schema/value.rb +3 -3
- data/lib/yarrow/version.rb +1 -1
- data/lib/yarrow.rb +0 -1
- metadata +2 -3
- data/lib/yarrow/schema.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0dba4f651517ceb22a806d2ac97637327983742ce4d6837ec0cc85cb4b9864c3
|
4
|
+
data.tar.gz: d7b2db29b33539da364b386023a662db2e4f5bcc009869444de005ae74f919fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b6b0550245ef7ac0f752c602bcc1a191a8260cf8e4a3553b77f1a600d82ebf773e97adcaffa2bc1ed1d913af9a32d5d183472fdabcabd9ba3e61a52cc9155eb
|
7
|
+
data.tar.gz: '099eeb8f8f90867144ad3ca2586d353b1b69e38af9534923c0856410b944592e48847b49650d0526af724f74851ad8f93205fc2032b864eb1a854c0d3f59475a'
|
data/lib/yarrow/config.rb
CHANGED
@@ -2,10 +2,12 @@ module Yarrow
|
|
2
2
|
module Schema
|
3
3
|
module Definitions
|
4
4
|
DEFINED_TYPES = {
|
5
|
-
string:
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
#string: Types::String,
|
6
|
+
string: Types::Instance.of(String),
|
7
|
+
#integer: Types::Integer,
|
8
|
+
integer: Types::Instance.of(Integer),
|
9
|
+
path: Types::Instance.of(Pathname),
|
10
|
+
any: Types::Any.new
|
9
11
|
}
|
10
12
|
|
11
13
|
def self.register(identifier, type_class)
|
@@ -23,6 +23,25 @@ module Yarrow
|
|
23
23
|
@attrs_spec.keys
|
24
24
|
end
|
25
25
|
|
26
|
+
def cast(input)
|
27
|
+
missing_attrs = @attrs_spec.keys.difference(input.keys)
|
28
|
+
|
29
|
+
if missing_attrs.any?
|
30
|
+
missing_attrs.each do |name|
|
31
|
+
raise "wrong number of attributes" unless @attrs_spec[name].is_a?(Types::Any)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
mismatching_attrs = input.keys.difference(@attrs_spec.keys)
|
36
|
+
|
37
|
+
raise "attribute does not exist" if mismatching_attrs.any?
|
38
|
+
|
39
|
+
input.reduce({}) do |converted, (name, value)|
|
40
|
+
converted[name] = @attrs_spec[name].cast(value)
|
41
|
+
converted
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
26
45
|
def check(input)
|
27
46
|
missing_attrs = @attrs_spec.keys.difference(input.keys)
|
28
47
|
|
data/lib/yarrow/schema/entity.rb
CHANGED
@@ -16,12 +16,9 @@ module Yarrow
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def initialize(config)
|
19
|
-
dictionary.
|
20
|
-
|
21
|
-
|
22
|
-
# end
|
23
|
-
#
|
24
|
-
config.each_pair do |key, value|
|
19
|
+
converted = dictionary.cast(config)
|
20
|
+
|
21
|
+
converted.each_pair do |key, value|
|
25
22
|
# raise "#{key} not a declared attribute" unless dictionary.key?(key)
|
26
23
|
#
|
27
24
|
# defined_type = dictionary[key]
|
data/lib/yarrow/schema/types.rb
CHANGED
@@ -24,10 +24,25 @@ module Yarrow
|
|
24
24
|
new(unit_type)
|
25
25
|
end
|
26
26
|
|
27
|
-
attr_reader :unit
|
27
|
+
attr_reader :unit, :accepts
|
28
28
|
|
29
29
|
def initialize(unit_type=nil)
|
30
30
|
@unit = unit_type
|
31
|
+
@accepts = {}
|
32
|
+
end
|
33
|
+
|
34
|
+
def accept(type, constructor)
|
35
|
+
accepts[type] = constructor
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
def should_coerce?(input)
|
40
|
+
accepts.key?(input.class)
|
41
|
+
end
|
42
|
+
|
43
|
+
def coerce(input)
|
44
|
+
constructor = accepts[input.class]
|
45
|
+
unit.send(constructor, input)
|
31
46
|
end
|
32
47
|
|
33
48
|
def check_instance_of!(input)
|
@@ -54,7 +69,10 @@ module Yarrow
|
|
54
69
|
end
|
55
70
|
end
|
56
71
|
|
57
|
-
def cast(input)
|
72
|
+
def cast(input)
|
73
|
+
return coerce(input) if should_coerce?(input)
|
74
|
+
check(input)
|
75
|
+
end
|
58
76
|
end
|
59
77
|
|
60
78
|
class Any < TypeClass
|
@@ -64,14 +82,14 @@ module Yarrow
|
|
64
82
|
end
|
65
83
|
|
66
84
|
class Instance < TypeClass
|
67
|
-
def
|
85
|
+
def check(input)
|
68
86
|
check_instance_of!(input)
|
69
87
|
input
|
70
88
|
end
|
71
89
|
end
|
72
90
|
|
73
91
|
class Kind < TypeClass
|
74
|
-
def
|
92
|
+
def check(input)
|
75
93
|
check_kind_of!(input)
|
76
94
|
input
|
77
95
|
end
|
@@ -94,7 +112,7 @@ module Yarrow
|
|
94
112
|
|
95
113
|
alias members unit
|
96
114
|
|
97
|
-
def
|
115
|
+
def check(input)
|
98
116
|
case implementation
|
99
117
|
when :any then check_respond_to_any!(input, members)
|
100
118
|
when :all then check_respond_to_all!(input, members)
|
@@ -104,7 +122,73 @@ module Yarrow
|
|
104
122
|
end
|
105
123
|
end
|
106
124
|
|
107
|
-
|
125
|
+
module CompoundType
|
126
|
+
def instance(unit_type)
|
127
|
+
@unit = Instance.of(unit_type)
|
128
|
+
self
|
129
|
+
end
|
130
|
+
|
131
|
+
def kind(unit_type)
|
132
|
+
@unit = Kind.of(unit_type)
|
133
|
+
self
|
134
|
+
end
|
135
|
+
|
136
|
+
def interface(*args)
|
137
|
+
@unit = Interface.of(args)
|
138
|
+
self
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
class List < TypeClass
|
143
|
+
include CompoundType
|
144
|
+
|
145
|
+
def self.of(unit_type)
|
146
|
+
new(Instance.of(unit_type))
|
147
|
+
end
|
148
|
+
|
149
|
+
def cast(input)
|
150
|
+
input.map do |item|
|
151
|
+
unit.cast(item)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
class Map < TypeClass
|
157
|
+
include CompoundType
|
158
|
+
|
159
|
+
def self.of(map_spec)
|
160
|
+
if map_spec.is_a?(Hash)
|
161
|
+
if map_spec.size == 1
|
162
|
+
key_type, value_type = map_spec.first
|
163
|
+
else
|
164
|
+
raise "map requires a single key => value type"
|
165
|
+
end
|
166
|
+
else
|
167
|
+
key_type = Symbol
|
168
|
+
value_type = map_spec
|
169
|
+
end
|
170
|
+
|
171
|
+
new(Instance.of(key_type), Instance.of(value_type))
|
172
|
+
end
|
173
|
+
|
174
|
+
attr_reader :key_type
|
175
|
+
alias value_type unit
|
176
|
+
|
177
|
+
def initialize(key_type, value_type)
|
178
|
+
@key_type = key_type
|
179
|
+
super(value_type)
|
180
|
+
end
|
181
|
+
|
182
|
+
def check(input)
|
183
|
+
keys = input.keys.map do |key|
|
184
|
+
key_type.cast(key)
|
185
|
+
end
|
186
|
+
values = input.values.map do |value|
|
187
|
+
value_type.cast(value)
|
188
|
+
end
|
189
|
+
|
190
|
+
[keys, values].transpose.to_h
|
191
|
+
end
|
108
192
|
end
|
109
193
|
end
|
110
194
|
end
|
data/lib/yarrow/schema/value.rb
CHANGED
data/lib/yarrow/version.rb
CHANGED
data/lib/yarrow.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yarrow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Rickerby
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mementus
|
@@ -242,7 +242,6 @@ files:
|
|
242
242
|
- lib/yarrow/process/project_manifest.rb
|
243
243
|
- lib/yarrow/process/step_processor.rb
|
244
244
|
- lib/yarrow/process/workflow.rb
|
245
|
-
- lib/yarrow/schema.rb
|
246
245
|
- lib/yarrow/schema/definitions.rb
|
247
246
|
- lib/yarrow/schema/dictionary.rb
|
248
247
|
- lib/yarrow/schema/entity.rb
|
data/lib/yarrow/schema.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require "delegate"
|
2
|
-
|
3
|
-
module Yarrow
|
4
|
-
module Schema
|
5
|
-
module Type
|
6
|
-
class Raw
|
7
|
-
class << self
|
8
|
-
def [](primitive)
|
9
|
-
@primitive = primitive
|
10
|
-
end
|
11
|
-
|
12
|
-
def new(input)
|
13
|
-
input
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class Any
|
19
|
-
end
|
20
|
-
# class Attribute
|
21
|
-
# class << self
|
22
|
-
# def accepts(attr_type)
|
23
|
-
# @accepts = attr_type
|
24
|
-
# end
|
25
|
-
# end
|
26
|
-
#
|
27
|
-
# attr_accessor :value
|
28
|
-
# alias_method :__getobj__, :value
|
29
|
-
#
|
30
|
-
# def initialize(value)
|
31
|
-
# raise "Invalid type" unless @accepts.is_a?(value.class)
|
32
|
-
# @value = value
|
33
|
-
# end
|
34
|
-
# end
|
35
|
-
#
|
36
|
-
# class Text < Attribute
|
37
|
-
# accepts String
|
38
|
-
# end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|