ree 1.0.35 → 1.0.37

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 430a09654fd1fefd69e6027549eb184dc873df7475d52aa4523c37e31e27cd43
4
- data.tar.gz: d80bac04108a35a65f62821d979f66efdc96d771c492f1c50bb64961fe0e95f2
3
+ metadata.gz: 5d501b79e7ddc962cae38fd84b12afe374275742acd074dc88596226e857b36b
4
+ data.tar.gz: 12f3f11d8e463facc2a0843865ab3e83bbd909e817bbe393142f4000b2ac0d24
5
5
  SHA512:
6
- metadata.gz: 5a8e1956af3506d256018cd74dbf9c9f77cfd20163aedff95b592c41da15fd80c9bc332e259b80d87500cae6c20df892936a0a8cf2fdc5d442fc95b885cbc40f
7
- data.tar.gz: 6479948915d542ca34491e51cb229b6d94d9f5c5a982ccb9816f11ca6c10627ebaf4c3bb3e19e66f39d67204043013479f4fe5b73faee2972f871b96e37a9486
6
+ metadata.gz: cf7fb8c65cdb57adc82bf645800e80e04d60be0f855d182276199b77afd566fad8d2465b74b01f0c1313165abf080b9b9a7e0ff36739fbb089712993d1829214
7
+ data.tar.gz: 8d6a0861d463fbd37731ddae4a7d603e93e04c3028d9e8af2717e31959067bb3e0328fd5a3112f61eb001ac186f34428d510101ebd0053fd8b4b3daa2a100323
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree (1.0.34)
4
+ ree (1.0.37)
5
5
  commander (~> 5.0.0)
6
6
 
7
7
  GEM
@@ -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
@@ -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
- def initialize(object_name, package_name, as)
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
 
@@ -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
- def link_object(object_name, as: nil, from: nil, import: nil)
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}
@@ -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
- eval_list.push(indent + "private attr_reader :#{_.as}")
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
- links.each do |_|
101
- pckg = @packages_facade.get_loaded_package(_.package_name)
102
- obj = pckg.get_object(_.object_name)
144
+ if !class_links.empty?
145
+ eval_list.push("\n")
146
+ eval_list.push("class << self")
147
+ indent = inc_indent(indent)
103
148
 
104
- if obj.fn?
105
- eval_list.push(indent + "\nprivate def #{_.as}(*args, **kwargs, &block)")
106
- indent = inc_indent(indent)
107
- eval_list.push(indent + "@#{_.as}.call(*args, **kwargs, &block)")
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
@@ -11,19 +11,28 @@ module Ree::RSpecLinkDSL
11
11
 
12
12
  define_method as do |*args, **kwargs, &proc|
13
13
  if obj.object?
14
- obj.klass.new
14
+ if obj.with_caller?
15
+ obj.klass.new.set_caller(self)
16
+ else
17
+ obj.klass.new
18
+ end
15
19
  else
16
- obj.klass.new.call(*args, **kwargs, &proc)
20
+ if obj.with_caller?
21
+ obj.klass.new.set_caller(self).call(*args, **kwargs, &proc)
22
+ else
23
+ obj.klass.new.call(*args, **kwargs, &proc)
24
+ end
17
25
  end
18
26
  end
19
27
  elsif obj_name.is_a?(String)
20
28
  const_list = link_file(from, obj_name, import_proc)
29
+
21
30
  const_list.each do |const|
22
31
  Object.const_set(const.name, self.const_get(const.name))
23
32
  end
24
33
  else
25
34
  raise Ree::Error.new("Invalid link DSL usage. Args should be Hash or String")
26
- end
35
+ end
27
36
  end
28
37
 
29
38
  private
data/lib/ree/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ree
4
- VERSION = "1.0.35"
4
+ VERSION = "1.0.37"
5
5
  end
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.35
4
+ version: 1.0.37
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-04-03 00:00:00.000000000 Z
11
+ date: 2024-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander