ree 1.0.34 → 1.0.36

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: 3e99db4aa81882cc0db13252390f2a7e50b734ebd6e13ba78f13fdfe80a89684
4
- data.tar.gz: 556285d5ced07101cb736d8e855abea3ff5e60a56dd4c95342dc82e4d4f3514a
3
+ metadata.gz: 40269b8b520f835a14d0b155cfb25408dfa0ec06bcdb48aaac552e96283cf76b
4
+ data.tar.gz: 58f6c405a3ab08def9dc2899a94c07cdf8cf0d7cf0fe051cfad6a13e77d81fbf
5
5
  SHA512:
6
- metadata.gz: bf697e027c817282f59f6533cc35aa244aa92942cc3d60be24ac4558db94e4c525509e22e20835dc573e7f0f8532f42acd6c3a618d97a9df75b4f61989234fe6
7
- data.tar.gz: 76aa018f20cead0705951697da550ac225f681aa50fb39c7bafff17f8c00384d72dcfc483a2d98804621dd2ffd221d22976c6bf45c0cf4e56aa4a15ac3e1919a
6
+ metadata.gz: 7b0dc9c0d912356c0bed577496d4af90714142d9774cfa3c093fc66f7937e3c04936ca8daed5ec3d796d9880db744f7ac11d7d1a91e33110a9959428e8ae02a1
7
+ data.tar.gz: 236477089e9ca29534fec178dd1d33181c1f8482c18fe8bddecd821787e55d69eacf8f51ee952a7070842ddb474d120f0760956d4749021e4c25557978fc3dc2
data/Gemfile.lock CHANGED
@@ -1,40 +1,44 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree (1.0.34)
4
+ ree (1.0.36)
5
5
  commander (~> 5.0.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- abbrev (0.1.2)
11
10
  commander (5.0.0)
12
11
  highline (~> 3.0.0)
13
- debug (1.6.2)
14
- irb (>= 1.3.6)
15
- reline (>= 0.3.1)
12
+ debug (1.9.1)
13
+ irb (~> 1.10)
14
+ reline (>= 0.3.8)
16
15
  diff-lcs (1.5.0)
17
- highline (3.0.0)
18
- abbrev
19
- io-console (0.5.11)
20
- irb (1.4.2)
21
- reline (>= 0.3.0)
22
- rake (13.0.6)
23
- reline (0.3.1)
16
+ highline (3.0.1)
17
+ io-console (0.7.2)
18
+ irb (1.11.1)
19
+ rdoc
20
+ reline (>= 0.4.2)
21
+ psych (5.1.2)
22
+ stringio
23
+ rake (13.1.0)
24
+ rdoc (6.6.2)
25
+ psych (>= 4.0.0)
26
+ reline (0.4.2)
24
27
  io-console (~> 0.5)
25
- rspec (3.11.0)
26
- rspec-core (~> 3.11.0)
27
- rspec-expectations (~> 3.11.0)
28
- rspec-mocks (~> 3.11.0)
29
- rspec-core (3.11.0)
30
- rspec-support (~> 3.11.0)
31
- rspec-expectations (3.11.0)
28
+ rspec (3.12.0)
29
+ rspec-core (~> 3.12.0)
30
+ rspec-expectations (~> 3.12.0)
31
+ rspec-mocks (~> 3.12.0)
32
+ rspec-core (3.12.2)
33
+ rspec-support (~> 3.12.0)
34
+ rspec-expectations (3.12.3)
32
35
  diff-lcs (>= 1.2.0, < 2.0)
33
- rspec-support (~> 3.11.0)
34
- rspec-mocks (3.11.1)
36
+ rspec-support (~> 3.12.0)
37
+ rspec-mocks (3.12.6)
35
38
  diff-lcs (>= 1.2.0, < 2.0)
36
- rspec-support (~> 3.11.0)
37
- rspec-support (3.11.0)
39
+ rspec-support (~> 3.12.0)
40
+ rspec-support (3.12.1)
41
+ stringio (3.1.0)
38
42
 
39
43
  PLATFORMS
40
44
  arm64-darwin-21
data/lib/ree/bean_dsl.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  module Ree::BeanDSL
4
4
  def self.included(base)
5
5
  base.extend(ClassMethods)
6
+ base.include(Ree::Inspectable)
6
7
  end
7
8
 
8
9
  def self.extended(base)
@@ -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}
data/lib/ree/fn_dsl.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  module Ree::FnDSL
4
4
  def self.included(base)
5
5
  base.extend(ClassMethods)
6
+ base.include(Ree::Inspectable)
6
7
  end
7
8
 
8
9
  def self.extended(base)
@@ -0,0 +1,10 @@
1
+ require "json"
2
+ require "objspace"
3
+
4
+ module Ree::Inspectable
5
+ def inspect
6
+ object_internals_json = ObjectSpace.dump(self)
7
+ address = JSON.parse(object_internals_json)["address"]
8
+ "#<#{self.class.name}:#{address}>"
9
+ end
10
+ end
@@ -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
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.34"
4
+ VERSION = "1.0.36"
5
5
  end
data/lib/ree.rb CHANGED
@@ -17,6 +17,7 @@ module Ree
17
17
  autoload :FnDSL, 'ree/fn_dsl'
18
18
  autoload :Gen, 'ree/gen'
19
19
  autoload :ImportDsl, 'ree/dsl/import_dsl'
20
+ autoload :Inspectable, 'ree/inspectable'
20
21
  autoload :LinkDSL, 'ree/link_dsl'
21
22
  autoload :LinkImportBuilder, 'ree/dsl/link_import_builder'
22
23
  autoload :LinkValidator, 'ree/core/link_validator'
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.34
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-01-18 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
@@ -156,6 +156,7 @@ files:
156
156
  - lib/ree/gen/init.rb
157
157
  - lib/ree/gen/package.rb
158
158
  - lib/ree/handlers/template_handler.rb
159
+ - lib/ree/inspectable.rb
159
160
  - lib/ree/link_dsl.rb
160
161
  - lib/ree/object_compiler.rb
161
162
  - lib/ree/package_dsl.rb