interfacets 0.9.9 → 0.99999
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/LICENSE +9 -17
- data/lib/interfacets/client/actor.rb +2 -1
- data/lib/interfacets/client/assets.rb +77 -63
- data/lib/interfacets/client/bus.rb +31 -8
- data/lib/interfacets/client/channels/api.rb +141 -35
- data/lib/interfacets/client/channels/audio.rb +13 -10
- data/lib/interfacets/client/channels/base.rb +2 -2
- data/lib/interfacets/client/channels/pubsub.rb +69 -0
- data/lib/interfacets/client/channels/react/builder.rb +42 -72
- data/lib/interfacets/client/channels/react/channel.rb +7 -5
- data/lib/interfacets/client/channels/react/evaluator.rb +6 -4
- data/lib/interfacets/client/channels/timer.rb +8 -7
- data/lib/interfacets/client/channels/url.rb +39 -6
- data/lib/interfacets/client/registry.rb +10 -70
- data/lib/interfacets/client/slots.rb +45 -0
- data/lib/interfacets/client/system.rb +20 -15
- data/lib/interfacets/client/template.rb +90 -0
- data/lib/interfacets/client/utils/mruby_patches.rb +8 -4
- data/lib/interfacets/client/utils/open_struct.rb +88 -77
- data/lib/interfacets/component_registry.rb +120 -0
- data/lib/interfacets/component_schema_parser.rb +88 -0
- data/lib/interfacets/mruby/build_config.rb +8 -4
- data/lib/interfacets/mruby/entrypoint.rb +2 -2
- data/lib/interfacets/server/api.rb +44 -27
- data/lib/interfacets/server/assets.rb +69 -28
- data/lib/interfacets/server/basic_router.rb +38 -23
- data/lib/interfacets/server/bus.rb +8 -14
- data/lib/interfacets/server/registry.rb +31 -185
- data/lib/interfacets/shared/basic_routable.rb +48 -0
- data/lib/interfacets/shared/entities/bus.rb +623 -177
- data/lib/interfacets/shared/entities/changeset.rb +432 -0
- data/lib/interfacets/shared/entities/collection_proxy.rb +132 -72
- data/lib/interfacets/shared/entities/specs/handlers.rb +74 -37
- data/lib/interfacets/shared/entities/specs.rb +223 -20
- data/lib/interfacets/shared/entity.rb +124 -110
- data/lib/interfacets/shared/entity_dsl.rb +272 -0
- data/lib/interfacets/shared/facet.rb +260 -0
- data/lib/interfacets/shared/generated_store.rb +74 -35
- data/lib/interfacets/shared/refreshable.rb +85 -0
- data/lib/interfacets/shared/utils.rb +36 -32
- data/lib/interfacets/shared/validations.rb +749 -25
- data/lib/interfacets/shared/view.rb +120 -0
- data/lib/interfacets/test/component_registry.rb +82 -0
- data/lib/interfacets/test/js/inline_bus.rb +68 -33
- data/lib/interfacets/test/js/nodo_bus.rb +37 -9
- data/lib/interfacets/test/js/receivers/api.rb +17 -4
- data/lib/interfacets/test/js/receivers/audio.rb +61 -0
- data/lib/interfacets/test/js/receivers/pubsub.rb +50 -0
- data/lib/interfacets/test/js/receivers/react/node/xml_parser.rb +103 -0
- data/lib/interfacets/test/js/receivers/react/node.rb +91 -71
- data/lib/interfacets/test/js/receivers/react.rb +15 -5
- data/lib/interfacets/test/js/receivers/timer.rb +81 -0
- data/lib/interfacets/test/js/receivers/url.rb +51 -10
- data/lib/interfacets/test/standard_elements.yml +173 -0
- data/lib/interfacets/test/ui_simulator.rb +145 -0
- data/lib/interfacets/test/validation_engine.rb +184 -0
- data/lib/interfacets/test.rb +1 -7
- data/lib/interfacets/version.rb +1 -1
- data/lib/interfacets.rb +13 -2
- metadata +51 -37
- data/.rubocop.yml +0 -180
- data/LICENSE.txt +0 -21
- data/Rakefile +0 -10
- data/lib/interfacets/client/channels/page_visibility.rb +0 -21
- data/lib/interfacets/client/channels/react/dom.rb +0 -91
- data/lib/interfacets/client/channels/speech_to_text.rb +0 -100
- data/lib/interfacets/client/config.rb +0 -22
- data/lib/interfacets/client/delegator.rb +0 -37
- data/lib/interfacets/client/facet.rb +0 -26
- data/lib/interfacets/client/facet2.rb +0 -15
- data/lib/interfacets/client/facets/attributes/accessor.rb +0 -28
- data/lib/interfacets/client/facets/attributes/association.rb +0 -50
- data/lib/interfacets/client/facets/attributes/bind.rb +0 -25
- data/lib/interfacets/client/facets/attributes/collection.rb +0 -47
- data/lib/interfacets/client/facets/attributes/readonly.rb +0 -19
- data/lib/interfacets/client/facets/deserializer.rb +0 -30
- data/lib/interfacets/client/facets/schema/deserializer.rb +0 -63
- data/lib/interfacets/client/facets/schema.rb +0 -63
- data/lib/interfacets/client/facets/serializer.rb +0 -18
- data/lib/interfacets/client/view.rb +0 -47
- data/lib/interfacets/server/assets/facet.rb +0 -61
- data/lib/interfacets/server/basic_routable.rb +0 -40
- data/lib/interfacets/server/config.rb +0 -87
- data/lib/interfacets/server/facet.rb +0 -51
- data/lib/interfacets/server/facets/deserializer.rb +0 -25
- data/lib/interfacets/server/facets/schema/serializer.rb +0 -54
- data/lib/interfacets/server/facets/serializer.rb +0 -50
- data/lib/interfacets/shared/entity_collection.rb +0 -88
- data/lib/interfacets/test/browser.rb +0 -63
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require("prism")
|
|
4
4
|
|
|
5
5
|
module Interfacets
|
|
6
6
|
module Server
|
|
7
7
|
module Assets
|
|
8
8
|
Const =
|
|
9
|
-
Data.define(
|
|
9
|
+
Data.define(
|
|
10
|
+
:nesting,
|
|
11
|
+
:type,
|
|
12
|
+
:name,
|
|
13
|
+
:parent
|
|
14
|
+
) do
|
|
10
15
|
def full_name
|
|
11
16
|
[nesting.last&.full_name, name].compact.join("::")
|
|
12
17
|
end
|
|
@@ -15,7 +20,7 @@ module Interfacets
|
|
|
15
20
|
class Classifier
|
|
16
21
|
class Visitor < Prism::Visitor
|
|
17
22
|
# This class just gathers up all modules and classes defined
|
|
18
|
-
attr_reader :
|
|
23
|
+
attr_reader(:mods, :stack)
|
|
19
24
|
def initialize
|
|
20
25
|
@stack = []
|
|
21
26
|
@mods = []
|
|
@@ -42,27 +47,32 @@ module Interfacets
|
|
|
42
47
|
)
|
|
43
48
|
|
|
44
49
|
const = Const.new(
|
|
45
|
-
nesting:
|
|
50
|
+
nesting: stack.dup,
|
|
46
51
|
name: node.constant_path.full_name,
|
|
47
52
|
type:,
|
|
48
53
|
parent:
|
|
49
54
|
)
|
|
50
|
-
|
|
51
|
-
mods <<
|
|
55
|
+
stack << const
|
|
56
|
+
mods << stack.dup
|
|
52
57
|
visit_child_nodes(node)
|
|
53
|
-
|
|
58
|
+
stack.pop
|
|
54
59
|
end
|
|
55
60
|
end
|
|
56
61
|
|
|
57
|
-
attr_reader
|
|
62
|
+
attr_reader(:code)
|
|
58
63
|
def initialize(code)
|
|
59
64
|
@code = code
|
|
60
65
|
end
|
|
61
66
|
|
|
62
67
|
def consts
|
|
63
68
|
@consts ||= (
|
|
64
|
-
Prism
|
|
65
|
-
|
|
69
|
+
Prism
|
|
70
|
+
.parse(code)
|
|
71
|
+
.value
|
|
72
|
+
.accept(visitor)
|
|
73
|
+
visitor
|
|
74
|
+
.mods
|
|
75
|
+
.map(&:last)
|
|
66
76
|
)
|
|
67
77
|
end
|
|
68
78
|
|
|
@@ -72,7 +82,7 @@ module Interfacets
|
|
|
72
82
|
end
|
|
73
83
|
|
|
74
84
|
class Serializer
|
|
75
|
-
attr_reader
|
|
85
|
+
attr_reader(:paths, :file)
|
|
76
86
|
def initialize(paths:, file: File)
|
|
77
87
|
@paths = paths
|
|
78
88
|
@file = file
|
|
@@ -97,7 +107,8 @@ module Interfacets
|
|
|
97
107
|
consts_by_path.fetch(path).each { |c| full_map[c.full_name] << path }
|
|
98
108
|
}
|
|
99
109
|
|
|
100
|
-
full_map
|
|
110
|
+
full_map
|
|
111
|
+
.transform_values(&:uniq!)
|
|
101
112
|
full_map
|
|
102
113
|
)
|
|
103
114
|
end
|
|
@@ -106,9 +117,9 @@ module Interfacets
|
|
|
106
117
|
serialized = {}
|
|
107
118
|
results = []
|
|
108
119
|
|
|
109
|
-
consts.each
|
|
120
|
+
consts.each do |const|
|
|
110
121
|
push_bootstrapper(const, results, serialized)
|
|
111
|
-
|
|
122
|
+
end
|
|
112
123
|
|
|
113
124
|
results
|
|
114
125
|
end
|
|
@@ -118,13 +129,23 @@ module Interfacets
|
|
|
118
129
|
|
|
119
130
|
serialized[const.full_name] = true
|
|
120
131
|
|
|
121
|
-
const.nesting.each do |
|
|
122
|
-
push_bootstrapper(
|
|
132
|
+
const.nesting.each do |nesting_const|
|
|
133
|
+
push_bootstrapper(
|
|
134
|
+
nesting_const,
|
|
135
|
+
results,
|
|
136
|
+
serialized
|
|
137
|
+
)
|
|
123
138
|
end
|
|
124
139
|
|
|
125
140
|
parent = (
|
|
126
141
|
if const.parent
|
|
127
|
-
resolve_const_name(
|
|
142
|
+
resolve_const_name(
|
|
143
|
+
const
|
|
144
|
+
.nesting
|
|
145
|
+
.last
|
|
146
|
+
&.full_name,
|
|
147
|
+
const.parent
|
|
148
|
+
)
|
|
128
149
|
end
|
|
129
150
|
)
|
|
130
151
|
|
|
@@ -145,13 +166,21 @@ module Interfacets
|
|
|
145
166
|
end
|
|
146
167
|
|
|
147
168
|
def resolve_const_name(nesting, name)
|
|
148
|
-
full_name =
|
|
169
|
+
full_name = (
|
|
170
|
+
[nesting, name]
|
|
171
|
+
.compact
|
|
172
|
+
.reject(&:empty?)
|
|
173
|
+
.join("::")
|
|
174
|
+
)
|
|
149
175
|
return consts_by_name[full_name] if consts_by_name.key?(full_name)
|
|
150
176
|
|
|
151
177
|
# maybe a constant that we don't handle loading for (eg, StandardError)
|
|
152
178
|
return name if nesting.nil? || nesting.empty?
|
|
153
179
|
|
|
154
|
-
resolve_const_name(
|
|
180
|
+
resolve_const_name(
|
|
181
|
+
nesting.split("::")[0...-1].join("::"),
|
|
182
|
+
name
|
|
183
|
+
)
|
|
155
184
|
end
|
|
156
185
|
|
|
157
186
|
def consts_by_name
|
|
@@ -159,7 +188,7 @@ module Interfacets
|
|
|
159
188
|
end
|
|
160
189
|
|
|
161
190
|
def fs_map
|
|
162
|
-
paths.map { [_1, file.read(_1)] }.to_h
|
|
191
|
+
@fs_map ||= paths.map { [_1, file.read(_1)] }.to_h
|
|
163
192
|
end
|
|
164
193
|
|
|
165
194
|
def consts
|
|
@@ -169,23 +198,35 @@ module Interfacets
|
|
|
169
198
|
def consts_by_path
|
|
170
199
|
@consts_by_path ||= (
|
|
171
200
|
fs_map
|
|
172
|
-
.transform_values {
|
|
201
|
+
.transform_values { Classifier.new(_1).consts }
|
|
173
202
|
)
|
|
174
203
|
end
|
|
175
204
|
end
|
|
176
205
|
|
|
177
206
|
GEM_DIRS = [
|
|
178
|
-
File.expand_path(
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
207
|
+
File.expand_path(
|
|
208
|
+
File.join(__dir__, "../shared")
|
|
209
|
+
),
|
|
210
|
+
File.expand_path(
|
|
211
|
+
File.join(__dir__, "../client")
|
|
212
|
+
),
|
|
213
|
+
File.expand_path(
|
|
214
|
+
File.join(__dir__, "../client.rb")
|
|
215
|
+
),
|
|
216
|
+
]
|
|
182
217
|
|
|
183
218
|
class << self
|
|
184
|
-
def bundle(dirs:, registry:)
|
|
219
|
+
def bundle(dirs:, registry:, only_facets: false)
|
|
185
220
|
|
|
186
|
-
|
|
221
|
+
target_dirs = (
|
|
222
|
+
if only_facets
|
|
223
|
+
dirs
|
|
224
|
+
else
|
|
225
|
+
GEM_DIRS + dirs
|
|
226
|
+
end
|
|
227
|
+
)
|
|
187
228
|
|
|
188
|
-
|
|
229
|
+
target_dirs
|
|
189
230
|
.flat_map { paths(_1) }
|
|
190
231
|
.flatten
|
|
191
232
|
.map(&:to_s)
|
|
@@ -3,22 +3,24 @@
|
|
|
3
3
|
module Interfacets
|
|
4
4
|
module Server
|
|
5
5
|
class BasicRouter
|
|
6
|
+
# Raised when no configured path (and no default) matches the url.
|
|
7
|
+
class NotFound < RuntimeError; end
|
|
8
|
+
|
|
6
9
|
class Evaluator
|
|
7
|
-
attr_reader
|
|
10
|
+
attr_reader(:bus)
|
|
8
11
|
def initialize(bus:)
|
|
9
12
|
@bus = bus
|
|
10
13
|
end
|
|
11
14
|
|
|
12
15
|
def call(klass:, id:, query:, resolved_path:)
|
|
13
|
-
klass.bus = bus
|
|
14
16
|
klass
|
|
15
|
-
.
|
|
16
|
-
.
|
|
17
|
+
.server_entity_class
|
|
18
|
+
.find_for_basic_routing(id, query:, bus:)
|
|
17
19
|
.tap { _1.entity.api_path = resolved_path }
|
|
18
20
|
end
|
|
19
21
|
end
|
|
20
22
|
|
|
21
|
-
attr_reader
|
|
23
|
+
attr_reader(:paths, :bus, :default)
|
|
22
24
|
def initialize(bus:, paths:, default: nil)
|
|
23
25
|
@bus = bus
|
|
24
26
|
@paths = paths
|
|
@@ -26,29 +28,35 @@ module Interfacets
|
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
def call(url, query: {})
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
evaluator.call(klass:, id: nil, query:, resolved_path: default)
|
|
32
|
-
end
|
|
31
|
+
path = normalize(url)
|
|
32
|
+
route_path, id, resolved_path = route_for(path)
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
evaluator.call(
|
|
35
|
+
klass: klass_for(route_path),
|
|
36
|
+
id:,
|
|
37
|
+
query:,
|
|
38
|
+
resolved_path:
|
|
39
|
+
)
|
|
40
|
+
end
|
|
38
41
|
|
|
39
|
-
|
|
42
|
+
# Returns [configured path, record id, resolved path]
|
|
43
|
+
def route_for(path)
|
|
44
|
+
if path.nil? && default
|
|
45
|
+
[default, nil, default]
|
|
46
|
+
elsif normalized_paths.key?(path)
|
|
47
|
+
[path, nil, path]
|
|
40
48
|
else
|
|
41
49
|
*parts, id = path.split("/")
|
|
42
|
-
|
|
50
|
+
base_path = parts.join("/")
|
|
43
51
|
|
|
44
|
-
if normalized_paths.key?(
|
|
45
|
-
|
|
46
|
-
evaluator.call(klass:, id:, query:, resolved_path: path)
|
|
52
|
+
if normalized_paths.key?(base_path)
|
|
53
|
+
[base_path, id, path]
|
|
47
54
|
elsif default
|
|
48
|
-
|
|
49
|
-
evaluator.call(klass:, id: nil, query:, resolved_path: default)
|
|
55
|
+
[default, nil, default]
|
|
50
56
|
else
|
|
51
|
-
raise
|
|
57
|
+
raise(
|
|
58
|
+
NotFound.new("unhandled route: #{path}")
|
|
59
|
+
)
|
|
52
60
|
end
|
|
53
61
|
end
|
|
54
62
|
end
|
|
@@ -58,7 +66,7 @@ module Interfacets
|
|
|
58
66
|
end
|
|
59
67
|
|
|
60
68
|
def klass_for(path)
|
|
61
|
-
val = normalized_paths.fetch(path)
|
|
69
|
+
val = normalized_paths.fetch(normalize(path))
|
|
62
70
|
|
|
63
71
|
(val.is_a?(String) ? Object.const_get(val) : val)
|
|
64
72
|
end
|
|
@@ -66,9 +74,16 @@ module Interfacets
|
|
|
66
74
|
def normalized_paths
|
|
67
75
|
@normalized_paths ||= (
|
|
68
76
|
paths
|
|
69
|
-
.transform_keys { _1
|
|
77
|
+
.transform_keys { normalize(_1) }
|
|
70
78
|
)
|
|
71
79
|
end
|
|
80
|
+
|
|
81
|
+
def normalize(path)
|
|
82
|
+
path
|
|
83
|
+
&.sub(/^#{bus.root_url}/, "/")
|
|
84
|
+
&.sub(/^/, "/")
|
|
85
|
+
&.sub(%r{^/*}, "/")
|
|
86
|
+
end
|
|
72
87
|
end
|
|
73
88
|
end
|
|
74
89
|
end
|
|
@@ -8,21 +8,19 @@ module Interfacets
|
|
|
8
8
|
:asset_paths,
|
|
9
9
|
:registry,
|
|
10
10
|
)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
root_url:,
|
|
14
|
-
asset_paths:,
|
|
15
|
-
facets:,
|
|
16
|
-
build_dir:
|
|
17
|
-
)
|
|
18
|
-
@registry = Registry.new(facets:, build_dir:)
|
|
11
|
+
def initialize(root_url:, asset_paths:)
|
|
12
|
+
@registry = Registry.new
|
|
19
13
|
@root_url = root_url
|
|
20
14
|
@asset_paths = asset_paths
|
|
21
15
|
end
|
|
22
16
|
|
|
23
|
-
def client_system_json
|
|
17
|
+
def client_system_json(only_facets: false)
|
|
24
18
|
{
|
|
25
|
-
assets: Assets.bundle(
|
|
19
|
+
assets: Assets.bundle(
|
|
20
|
+
dirs: asset_paths,
|
|
21
|
+
registry:,
|
|
22
|
+
only_facets:
|
|
23
|
+
),
|
|
26
24
|
root_url:
|
|
27
25
|
}
|
|
28
26
|
end
|
|
@@ -30,10 +28,6 @@ module Interfacets
|
|
|
30
28
|
def build(name:, store:)
|
|
31
29
|
registry.build(name, store)
|
|
32
30
|
end
|
|
33
|
-
|
|
34
|
-
def handle(name:, id:, event:)
|
|
35
|
-
registry.load(name, id).handle(event)
|
|
36
|
-
end
|
|
37
31
|
end
|
|
38
32
|
end
|
|
39
33
|
end
|
|
@@ -1,212 +1,58 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require("active_support/all")
|
|
4
|
+
require("ostruct")
|
|
4
5
|
|
|
5
6
|
module Interfacets
|
|
6
7
|
module Server
|
|
7
8
|
class Registry
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@build_dir = build_dir
|
|
11
|
-
@specs = Array(facets)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def register
|
|
15
|
-
specs
|
|
16
|
-
.flat_map { _1.respond_to?(:call) ? _1.call : _1 }
|
|
17
|
-
.each do |klass_or_name|
|
|
18
|
-
|
|
19
|
-
klass = (
|
|
20
|
-
if klass_or_name.is_a?(String)
|
|
21
|
-
if registry.key?(klass_or_name)
|
|
22
|
-
next
|
|
23
|
-
else
|
|
24
|
-
Object.const_get(klass_or_name)
|
|
25
|
-
end
|
|
26
|
-
else
|
|
27
|
-
klass_or_name
|
|
28
|
-
end
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
next if registry.key?(klass.name)
|
|
32
|
-
|
|
33
|
-
shared = Class.new(Shared::Entity) do
|
|
34
|
-
klass.shareds.each { class_exec(&_1) }
|
|
35
|
-
end
|
|
9
|
+
class Channel
|
|
10
|
+
attr_reader(:facet)
|
|
36
11
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
12
|
+
attr_reader(:registry)
|
|
13
|
+
def initialize(registry:)
|
|
14
|
+
@registry = registry
|
|
15
|
+
end
|
|
40
16
|
|
|
41
|
-
|
|
42
|
-
|
|
17
|
+
def render_facet(in_reply_to:)
|
|
18
|
+
facet.render(in_reply_to:)
|
|
19
|
+
end
|
|
43
20
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
end
|
|
48
|
-
end
|
|
21
|
+
def rendered?
|
|
22
|
+
facet
|
|
23
|
+
end
|
|
49
24
|
|
|
50
|
-
|
|
51
|
-
|
|
25
|
+
def render(klass, store)
|
|
26
|
+
@facet = registry.build(klass, store)
|
|
27
|
+
end
|
|
52
28
|
end
|
|
53
29
|
|
|
54
30
|
def build(name, store)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
31
|
+
facet = name.is_a?(Module) ? name : Object.const_get(name)
|
|
32
|
+
if facet.name.nil?
|
|
33
|
+
raise(
|
|
34
|
+
ArgumentError.new(
|
|
35
|
+
"Facet #{facet.inspect} must be a named module: " \
|
|
36
|
+
"the client looks facets up by constant name"
|
|
37
|
+
)
|
|
38
|
+
)
|
|
39
|
+
end
|
|
59
40
|
|
|
60
41
|
Api.new(
|
|
61
42
|
registry: self,
|
|
62
43
|
name:,
|
|
63
44
|
entity: (
|
|
64
|
-
|
|
65
|
-
.
|
|
45
|
+
facet
|
|
46
|
+
.server_entity_class
|
|
66
47
|
.new(
|
|
67
48
|
store: store.is_a?(Hash) ? OpenStruct.new(store) : store,
|
|
68
|
-
nesting:
|
|
69
|
-
parent: nil
|
|
49
|
+
nesting: "root",
|
|
50
|
+
parent: nil,
|
|
51
|
+
channel: Channel.new(registry: self)
|
|
70
52
|
)
|
|
71
53
|
)
|
|
72
54
|
)
|
|
73
55
|
end
|
|
74
|
-
|
|
75
|
-
def serialize
|
|
76
|
-
register
|
|
77
|
-
FileUtils.mkdir_p(build_dir)
|
|
78
|
-
|
|
79
|
-
registry.each do |name, entry|
|
|
80
|
-
base_name = "#{name}::Client"
|
|
81
|
-
|
|
82
|
-
header = ""
|
|
83
|
-
footer = ""
|
|
84
|
-
nesting = []
|
|
85
|
-
name.split("::").each do |mod|
|
|
86
|
-
nesting << mod
|
|
87
|
-
footer += "\nend"
|
|
88
|
-
header +=(
|
|
89
|
-
if nesting.join("::").constantize.is_a?(Class)
|
|
90
|
-
"\nclass #{mod}"
|
|
91
|
-
else
|
|
92
|
-
"\nmodule #{mod}"
|
|
93
|
-
end
|
|
94
|
-
)
|
|
95
|
-
end
|
|
96
|
-
header += "\nmodule Client"
|
|
97
|
-
footer += "\nend"
|
|
98
|
-
|
|
99
|
-
File.write(
|
|
100
|
-
File.join(build_dir, path_for("#{base_name}::Shared")),
|
|
101
|
-
<<~TXT
|
|
102
|
-
#{header}
|
|
103
|
-
class Shared < Interfacets::Shared::Entity
|
|
104
|
-
#{
|
|
105
|
-
entry
|
|
106
|
-
.fetch(:klass)
|
|
107
|
-
.shareds
|
|
108
|
-
.map { write_source(_1) }
|
|
109
|
-
.map { "class_exec(&#{_1})" }
|
|
110
|
-
.join("\n")
|
|
111
|
-
}
|
|
112
|
-
end
|
|
113
|
-
#{footer}
|
|
114
|
-
TXT
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
File.write(
|
|
118
|
-
File.join(build_dir, path_for("#{base_name}::View")),
|
|
119
|
-
<<~TXT
|
|
120
|
-
#{header}
|
|
121
|
-
class View < Interfacets::Client::View
|
|
122
|
-
#{
|
|
123
|
-
entry
|
|
124
|
-
.fetch(:klass)
|
|
125
|
-
.views
|
|
126
|
-
.map { write_source(_1) }
|
|
127
|
-
.map { "view(&#{_1})"}
|
|
128
|
-
.join("\n")
|
|
129
|
-
}
|
|
130
|
-
end
|
|
131
|
-
#{footer}
|
|
132
|
-
TXT
|
|
133
|
-
)
|
|
134
|
-
|
|
135
|
-
File.write(
|
|
136
|
-
File.join(build_dir, path_for("#{base_name}::Entity")),
|
|
137
|
-
<<~TXT
|
|
138
|
-
#{header}
|
|
139
|
-
class Entity < Interfacets::Shared::Entity
|
|
140
|
-
class << self
|
|
141
|
-
def view
|
|
142
|
-
#{base_name}::View
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
def store
|
|
146
|
-
@store ||= (
|
|
147
|
-
::Interfacets::Shared::GeneratedStore.construct(self)
|
|
148
|
-
.tap { self.const_set("Store", _1) }
|
|
149
|
-
)
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
role("client")
|
|
154
|
-
|
|
155
|
-
#{
|
|
156
|
-
entry
|
|
157
|
-
.fetch(:klass)
|
|
158
|
-
.shareds
|
|
159
|
-
.map { write_source(_1) }
|
|
160
|
-
.map { "class_exec(&#{_1})" }
|
|
161
|
-
.join("\n")
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
#{
|
|
165
|
-
entry
|
|
166
|
-
.fetch(:klass)
|
|
167
|
-
.clients
|
|
168
|
-
.map { write_source(_1) }
|
|
169
|
-
.map { "class_exec(&#{_1})" }
|
|
170
|
-
.join("\n")
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
self.manifest = Shared
|
|
174
|
-
|
|
175
|
-
actions.each do |name, spec|
|
|
176
|
-
if name.start_with?("after_")
|
|
177
|
-
define_method(name) {}
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
def channel(name)
|
|
182
|
-
Interfacets::Client::System.current_bus.channel(name).builder
|
|
183
|
-
end
|
|
184
|
-
end
|
|
185
|
-
#{footer}
|
|
186
|
-
TXT
|
|
187
|
-
)
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
def registry
|
|
192
|
-
@registry ||= {}
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
private
|
|
196
|
-
|
|
197
|
-
def path_for(class_name)
|
|
198
|
-
"#{class_name.gsub("::", "-")}.rb"
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
def write_source(block)
|
|
202
|
-
return unless block
|
|
203
|
-
|
|
204
|
-
RubyVM::AbstractSyntaxTree
|
|
205
|
-
.of(block, keep_script_lines: true)
|
|
206
|
-
.source
|
|
207
|
-
.then { block.is_a?(UnboundMethod) ? _1 : "lambda #{_1}" }
|
|
208
|
-
.strip
|
|
209
|
-
end
|
|
210
56
|
end
|
|
211
57
|
end
|
|
212
58
|
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Interfacets
|
|
4
|
+
module Shared
|
|
5
|
+
module BasicRoutable
|
|
6
|
+
extend(ActiveSupport::Concern)
|
|
7
|
+
|
|
8
|
+
included do
|
|
9
|
+
class << self
|
|
10
|
+
attr_accessor(:bus)
|
|
11
|
+
|
|
12
|
+
def build(klass, store)
|
|
13
|
+
bus.registry.build(klass, store)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# This is unfortunate, but in order to be able to do:
|
|
18
|
+
|
|
19
|
+
# build(self, ...)
|
|
20
|
+
# we need the self to be the facet.
|
|
21
|
+
# We could also update the registry to handle being passed a server
|
|
22
|
+
# entity, but I'm currently tweaking the registry. so this is a TODO.
|
|
23
|
+
facet = self
|
|
24
|
+
|
|
25
|
+
entity_base do
|
|
26
|
+
accessor(
|
|
27
|
+
:api_path,
|
|
28
|
+
accepted_by: :client
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
server_entity(unshift: true) do
|
|
33
|
+
attr_accessor(:api_path)
|
|
34
|
+
|
|
35
|
+
define_singleton_method(:find) do |&block|
|
|
36
|
+
@find = block if block
|
|
37
|
+
@find
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
define_singleton_method(:find_for_basic_routing) do |id, query:, bus:|
|
|
41
|
+
facet.bus = bus
|
|
42
|
+
facet.instance_exec(id, query:, &find)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|