ree 1.0.35 → 1.0.36
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/ree/core/object.rb +23 -1
- data/lib/ree/core/object_link.rb +4 -2
- data/lib/ree/dsl/object_dsl.rb +44 -2
- data/lib/ree/object_compiler.rb +95 -16
- data/lib/ree/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40269b8b520f835a14d0b155cfb25408dfa0ec06bcdb48aaac552e96283cf76b
|
4
|
+
data.tar.gz: 58f6c405a3ab08def9dc2899a94c07cdf8cf0d7cf0fe051cfad6a13e77d81fbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b0dc9c0d912356c0bed577496d4af90714142d9774cfa3c093fc66f7937e3c04936ca8daed5ec3d796d9880db744f7ac11d7d1a91e33110a9959428e8ae02a1
|
7
|
+
data.tar.gz: 236477089e9ca29534fec178dd1d33181c1f8482c18fe8bddecd821787e55d69eacf8f51ee952a7070842ddb474d120f0760956d4749021e4c25557978fc3dc2
|
data/Gemfile.lock
CHANGED
data/lib/ree/core/object.rb
CHANGED
@@ -5,7 +5,7 @@ class Ree::Object
|
|
5
5
|
:package_name, :factory, :after_init,
|
6
6
|
:class_name, :links, :mount_as, :freeze,
|
7
7
|
:errors, :linked_const_list, :compiled_frozen,
|
8
|
-
:singleton, :tags
|
8
|
+
:singleton, :tags, :target, :with_caller
|
9
9
|
|
10
10
|
# @param [Symbol] name Object name
|
11
11
|
# @param [String] schema_rpath Object schema path relative to project root dir
|
@@ -16,10 +16,12 @@ class Ree::Object
|
|
16
16
|
@rpath = rpath
|
17
17
|
@links = []
|
18
18
|
@errors = []
|
19
|
+
@target = :object
|
19
20
|
@loaded = false
|
20
21
|
@freeze = true
|
21
22
|
@compiled = false
|
22
23
|
@singleton = false
|
24
|
+
@with_caller = false
|
23
25
|
@compiled_frozen = @freeze
|
24
26
|
@linked_const_list = []
|
25
27
|
@tags = []
|
@@ -28,6 +30,8 @@ class Ree::Object
|
|
28
30
|
def reset
|
29
31
|
@compiled = false
|
30
32
|
@singleton = false
|
33
|
+
@with_caller = false
|
34
|
+
@target = :object
|
31
35
|
@loaded = false
|
32
36
|
@factory = nil
|
33
37
|
@after_init = nil
|
@@ -55,6 +59,10 @@ class Ree::Object
|
|
55
59
|
@compiled_frozen = @freeze
|
56
60
|
end
|
57
61
|
|
62
|
+
def with_caller?
|
63
|
+
@with_caller
|
64
|
+
end
|
65
|
+
|
58
66
|
def compiled?
|
59
67
|
@compiled
|
60
68
|
end
|
@@ -79,6 +87,15 @@ class Ree::Object
|
|
79
87
|
@freeze
|
80
88
|
end
|
81
89
|
|
90
|
+
def singleton?
|
91
|
+
@singleton
|
92
|
+
end
|
93
|
+
|
94
|
+
# @param [Symbol] val Object linking target (:object, :class, :both)
|
95
|
+
def set_target(val)
|
96
|
+
@target = val; self
|
97
|
+
end
|
98
|
+
|
82
99
|
# @param [Symbol] val Object mount as type (:fn or :bean)
|
83
100
|
def set_mount_as(val)
|
84
101
|
@mount_as = val; self
|
@@ -93,6 +110,11 @@ class Ree::Object
|
|
93
110
|
@singleton = true; self
|
94
111
|
end
|
95
112
|
|
113
|
+
|
114
|
+
def set_as_with_caller
|
115
|
+
@with_caller = true; self
|
116
|
+
end
|
117
|
+
|
96
118
|
def object?
|
97
119
|
@mount_as == :object
|
98
120
|
end
|
data/lib/ree/core/object_link.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Ree::ObjectLink
|
4
|
-
attr_reader :object_name, :package_name, :as, :constants
|
4
|
+
attr_reader :object_name, :package_name, :as, :constants, :target
|
5
5
|
|
6
6
|
# @param [Symbol] object_name Linked object name
|
7
7
|
# @param [Symbol] package_name Linked object package
|
8
8
|
# @param [Symbol] as Linked object alias name
|
9
|
-
|
9
|
+
# @param Nilor[Symbol] target Linked object target
|
10
|
+
def initialize(object_name, package_name, as, target)
|
10
11
|
@object_name = object_name
|
11
12
|
@package_name = package_name
|
12
13
|
@as = as
|
14
|
+
@target = target
|
13
15
|
@constants = []
|
14
16
|
end
|
15
17
|
|
data/lib/ree/dsl/object_dsl.rb
CHANGED
@@ -45,11 +45,13 @@ class Ree::ObjectDsl
|
|
45
45
|
# @param [Nilor[Symbol]] as
|
46
46
|
# @param [Nilor[Symbol]] from
|
47
47
|
# @param [Nilor[Proc]] import
|
48
|
-
|
48
|
+
# @param [Or[:object, :class, :both]] import
|
49
|
+
def link_object(object_name, as: nil, from: nil, import: nil, target: nil)
|
49
50
|
check_arg(object_name, :object_name, Symbol)
|
50
51
|
check_arg(as, :as, Symbol) if as
|
51
52
|
check_arg(from, :from, Symbol) if from
|
52
53
|
check_arg(import, :import, Proc) if import
|
54
|
+
check_target(target) if target
|
53
55
|
|
54
56
|
link_package_name = from.nil? ? @object.package_name : from
|
55
57
|
link_object_name = object_name
|
@@ -69,7 +71,7 @@ class Ree::ObjectDsl
|
|
69
71
|
end
|
70
72
|
|
71
73
|
link = Ree::ObjectLink.new(
|
72
|
-
link_object_name, link_package_name, link_as
|
74
|
+
link_object_name, link_package_name, link_as, target
|
73
75
|
)
|
74
76
|
|
75
77
|
if const_list
|
@@ -83,6 +85,28 @@ class Ree::ObjectDsl
|
|
83
85
|
@packages_facade.load_package_object(link_package_name, link_object_name)
|
84
86
|
end
|
85
87
|
|
88
|
+
# @param [Symbol] target (:object, :class, :both, default: :object)
|
89
|
+
def target(val)
|
90
|
+
check_arg(val, :target, Symbol)
|
91
|
+
check_target(val)
|
92
|
+
|
93
|
+
@object.set_target(val)
|
94
|
+
end
|
95
|
+
|
96
|
+
def with_caller
|
97
|
+
@object.set_freeze(false)
|
98
|
+
|
99
|
+
if @object.singleton?
|
100
|
+
raise_error("`with_caller` is not available for singletons")
|
101
|
+
end
|
102
|
+
|
103
|
+
if @object.factory?
|
104
|
+
raise_error("`with_caller` is not available for factory beans")
|
105
|
+
end
|
106
|
+
|
107
|
+
@object.set_as_with_caller
|
108
|
+
end
|
109
|
+
|
86
110
|
# @param [Symbol] method_name
|
87
111
|
def factory(method_name)
|
88
112
|
if !@object.object?
|
@@ -93,11 +117,19 @@ class Ree::ObjectDsl
|
|
93
117
|
raise_error("Factory beans do not support after_init DSL")
|
94
118
|
end
|
95
119
|
|
120
|
+
if @object.with_caller?
|
121
|
+
raise_error("Factory beans do not support with_caller DSL")
|
122
|
+
end
|
123
|
+
|
96
124
|
check_arg(method_name, :method_name, Symbol)
|
97
125
|
@object.set_factory(method_name)
|
98
126
|
end
|
99
127
|
|
100
128
|
def singleton
|
129
|
+
if @object.with_caller?
|
130
|
+
raise_error("`singleton` should not be combined with `with_caller`")
|
131
|
+
end
|
132
|
+
|
101
133
|
@object.set_as_singleton
|
102
134
|
end
|
103
135
|
|
@@ -113,6 +145,10 @@ class Ree::ObjectDsl
|
|
113
145
|
|
114
146
|
# @param [Bool] flag
|
115
147
|
def freeze(flag)
|
148
|
+
if @object.with_caller? && flag
|
149
|
+
raise_error("`freeze` should not be combined with `with_caller`")
|
150
|
+
end
|
151
|
+
|
116
152
|
check_bool(flag, :flag)
|
117
153
|
@object.set_freeze(flag)
|
118
154
|
end
|
@@ -277,6 +313,12 @@ class Ree::ObjectDsl
|
|
277
313
|
end
|
278
314
|
end
|
279
315
|
|
316
|
+
def check_target(val)
|
317
|
+
if ![:object, :class, :both].include?(val)
|
318
|
+
raise Ree::Error.new("target should be one of [:object, :class, :both]", :invalid_dsl_usage)
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
280
322
|
def raise_error(text, code = :invalid_dsl_usage)
|
281
323
|
msg = <<~DOC
|
282
324
|
object: :#{@object.name}
|
data/lib/ree/object_compiler.rb
CHANGED
@@ -18,13 +18,57 @@ class Ree::ObjectCompiler
|
|
18
18
|
|
19
19
|
klass = object.klass
|
20
20
|
links = object.links
|
21
|
+
|
22
|
+
links.each do |_|
|
23
|
+
@link_validator.call(object, _)
|
24
|
+
pckg = @packages_facade.get_loaded_package(_.package_name)
|
25
|
+
obj = pckg.get_object(_.object_name)
|
26
|
+
@packages_facade.load_package_object(pckg.name, obj.name)
|
27
|
+
end
|
28
|
+
|
21
29
|
eval_list = []
|
22
30
|
|
23
31
|
eval_list.push("\n# #{object.klass}")
|
24
32
|
indent = ""
|
25
33
|
|
34
|
+
if object.with_caller?
|
35
|
+
eval_list.push("def get_caller = @caller")
|
36
|
+
eval_list.push("\n")
|
37
|
+
eval_list.push("def set_caller(c)")
|
38
|
+
indent = inc_indent(indent)
|
39
|
+
eval_list.push("@caller = c")
|
40
|
+
eval_list.push("self")
|
41
|
+
indent = dec_indent(indent)
|
42
|
+
eval_list.push("end")
|
43
|
+
end
|
44
|
+
|
45
|
+
class_links = []
|
46
|
+
object_links = []
|
47
|
+
|
26
48
|
links.each do |_|
|
27
|
-
|
49
|
+
pckg = @packages_facade.get_loaded_package(_.package_name)
|
50
|
+
obj = pckg.get_object(_.object_name)
|
51
|
+
|
52
|
+
if [:class, :both].include?(_.target || obj.target)
|
53
|
+
class_links << _
|
54
|
+
end
|
55
|
+
|
56
|
+
if [:object, :both].include?(_.target || obj.target)
|
57
|
+
object_links << _
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
if !class_links.empty?
|
62
|
+
class_links.each do |_|
|
63
|
+
pckg = @packages_facade.get_loaded_package(_.package_name)
|
64
|
+
obj = pckg.get_object(_.object_name)
|
65
|
+
|
66
|
+
if !obj.with_caller?
|
67
|
+
eval_list.push(indent + "@#{_.as} = #{obj.klass}.new")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
eval_list.push("\n")
|
28
72
|
end
|
29
73
|
|
30
74
|
eval_list.push("\n")
|
@@ -97,23 +141,26 @@ class Ree::ObjectCompiler
|
|
97
141
|
|
98
142
|
eval_list.push(indent + 'end')
|
99
143
|
|
100
|
-
|
101
|
-
|
102
|
-
|
144
|
+
if !class_links.empty?
|
145
|
+
eval_list.push("\n")
|
146
|
+
eval_list.push("class << self")
|
147
|
+
indent = inc_indent(indent)
|
103
148
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
eval_list
|
108
|
-
indent = dec_indent(indent)
|
109
|
-
eval_list.push(indent + "end")
|
110
|
-
else
|
111
|
-
eval_list.push(indent + "\nprivate def #{_.as}")
|
112
|
-
indent = inc_indent(indent)
|
113
|
-
eval_list.push(indent + "@#{_.as}")
|
114
|
-
indent = dec_indent(indent)
|
115
|
-
eval_list.push(indent + "end")
|
149
|
+
class_links.each do |_|
|
150
|
+
pckg = @packages_facade.get_loaded_package(_.package_name)
|
151
|
+
obj = pckg.get_object(_.object_name)
|
152
|
+
mount_fn(eval_list, obj, indent, _)
|
116
153
|
end
|
154
|
+
|
155
|
+
indent = dec_indent(indent)
|
156
|
+
eval_list.push("end")
|
157
|
+
eval_list.push("\n")
|
158
|
+
end
|
159
|
+
|
160
|
+
object_links.each do |_|
|
161
|
+
pckg = @packages_facade.get_loaded_package(_.package_name)
|
162
|
+
obj = pckg.get_object(_.object_name)
|
163
|
+
mount_fn(eval_list, obj, indent, _)
|
117
164
|
end
|
118
165
|
|
119
166
|
indent = dec_indent(indent)
|
@@ -139,6 +186,38 @@ class Ree::ObjectCompiler
|
|
139
186
|
|
140
187
|
private
|
141
188
|
|
189
|
+
def mount_fn(eval_list, obj, indent, object_link)
|
190
|
+
if obj.fn?
|
191
|
+
if obj.with_caller?
|
192
|
+
eval_list.push(indent + "private def #{object_link.as}(*args, **kwargs, &block)")
|
193
|
+
indent = inc_indent(indent)
|
194
|
+
eval_list.push(indent + "#{obj.klass}.new.set_caller(self).call(*args, **kwargs, &block)")
|
195
|
+
indent = dec_indent(indent)
|
196
|
+
eval_list.push(indent + "end")
|
197
|
+
else
|
198
|
+
eval_list.push(indent + "private def #{object_link.as}(*args, **kwargs, &block)")
|
199
|
+
indent = inc_indent(indent)
|
200
|
+
eval_list.push(indent + "@#{object_link.as}.call(*args, **kwargs, &block)")
|
201
|
+
indent = dec_indent(indent)
|
202
|
+
eval_list.push(indent + "end")
|
203
|
+
end
|
204
|
+
else
|
205
|
+
if obj.with_caller?
|
206
|
+
eval_list.push(indent + "private def #{object_link.as}")
|
207
|
+
indent = inc_indent(indent)
|
208
|
+
eval_list.push(indent + "@#{object_link.as}")
|
209
|
+
indent = dec_indent(indent)
|
210
|
+
eval_list.push(indent + "end")
|
211
|
+
else
|
212
|
+
eval_list.push(indent + "private def #{object_link.as}")
|
213
|
+
indent = inc_indent(indent)
|
214
|
+
eval_list.push(indent + "@#{object_link.as}")
|
215
|
+
indent = dec_indent(indent)
|
216
|
+
eval_list.push(indent + "end")
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
142
221
|
def inc_indent(indent)
|
143
222
|
indent += " "
|
144
223
|
end
|
data/lib/ree/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.36
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ruslan Gatiyatov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|