ree 1.0.29 → 1.0.31
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/Gemfile.lock +1 -1
- data/lib/ree/dsl/import_dsl.rb +45 -12
- data/lib/ree/dsl/link_import_builder.rb +19 -5
- data/lib/ree/dsl/object_dsl.rb +7 -39
- data/lib/ree/templates/init/ree.setup.rb +0 -7
- data/lib/ree/version.rb +1 -1
- data/lib/ree.rb +0 -13
- metadata +2 -3
- data/lib/ree/dsl/error_builder.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6d6548b0d788689ab62d295a88602cfe8e555ed00879898118a9fa6335e63d8
|
4
|
+
data.tar.gz: d36aa35b5d3e5c3b618ec5037c28590249ad8d0aefa1633a01564fe6e8806039
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b4eeb250100dd7dd1affcd9ba71b2659b18166686082612c4929282a70f22d5b477f9468e5610df4186a6c5c2e499fc81bcd10511905172923f77cd4fc3336d
|
7
|
+
data.tar.gz: 0b59b6a98b4ec333c22a1f857b26d83294ba09b199dadce5e5575f64cc68fdf16f1ee6dbcf57108eb04f8dc003f9880fd04be5b975725a121cc075096b69ebf9
|
data/Gemfile.lock
CHANGED
data/lib/ree/dsl/import_dsl.rb
CHANGED
@@ -1,21 +1,24 @@
|
|
1
1
|
# frozen_string_literal = true
|
2
2
|
|
3
3
|
class Ree::ImportDsl
|
4
|
+
def initialize
|
5
|
+
setup_removed_constants
|
6
|
+
end
|
7
|
+
|
4
8
|
def execute(klass, proc)
|
5
|
-
self.class.instance_exec(&proc)
|
6
|
-
rescue Ree::ImportDsl::UnlinkConstError => e
|
7
|
-
const_removed = remove_or_assign_const(klass, e.const)
|
9
|
+
class_constant = self.class.instance_exec(&proc)
|
8
10
|
|
9
|
-
|
11
|
+
[
|
12
|
+
extract_constants(class_constant),
|
13
|
+
get_removed_constants
|
14
|
+
]
|
15
|
+
rescue Ree::ImportDsl::UnlinkConstError => e
|
16
|
+
retry_after = remove_or_assign_const(klass, e.const)
|
17
|
+
retry if retry_after
|
10
18
|
rescue NoMethodError => e
|
11
|
-
if e.name == :&
|
12
|
-
|
13
|
-
|
14
|
-
if const_removed
|
15
|
-
retry
|
16
|
-
else
|
17
|
-
raise Ree::Error.new("'#{e.receiver}' already linked or defined in '#{klass}'", :invalid_dsl_usage)
|
18
|
-
end
|
19
|
+
if e.name == :& || e.name == :as
|
20
|
+
retry_after = remove_or_assign_const(klass, e.receiver)
|
21
|
+
retry if retry_after
|
19
22
|
else
|
20
23
|
raise e
|
21
24
|
end
|
@@ -27,6 +30,27 @@ class Ree::ImportDsl
|
|
27
30
|
retry
|
28
31
|
end
|
29
32
|
|
33
|
+
private def extract_constants(class_constant)
|
34
|
+
[class_constant] + class_constant.constants
|
35
|
+
end
|
36
|
+
|
37
|
+
private def setup_removed_constants
|
38
|
+
self.class.instance_variable_set(:@removed_constants, [])
|
39
|
+
end
|
40
|
+
|
41
|
+
private def get_removed_constants
|
42
|
+
self.class.instance_variable_get(:@removed_constants)
|
43
|
+
end
|
44
|
+
|
45
|
+
class RemovedConstant
|
46
|
+
attr_reader :name, :const
|
47
|
+
|
48
|
+
def initialize(name, const)
|
49
|
+
@name = name
|
50
|
+
@const = const
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
30
54
|
class UnlinkConstError < StandardError
|
31
55
|
attr_reader :const
|
32
56
|
|
@@ -92,11 +116,15 @@ class Ree::ImportDsl
|
|
92
116
|
if constant.is_a?(Class) || constant.is_a?(Module)
|
93
117
|
if (const.is_a?(Class) || const.is_a?(Module)) && const.name == constant.name
|
94
118
|
klass.send(:remove_const, const_sym)
|
119
|
+
store_removed_constant(const_sym, constant)
|
120
|
+
|
95
121
|
retry_after = true
|
96
122
|
break
|
97
123
|
end
|
98
124
|
elsif const == constant
|
99
125
|
klass.send(:remove_const, const_sym)
|
126
|
+
store_removed_constant(const_sym, constant)
|
127
|
+
|
100
128
|
retry_after = true
|
101
129
|
break
|
102
130
|
end
|
@@ -122,6 +150,11 @@ class Ree::ImportDsl
|
|
122
150
|
|
123
151
|
private
|
124
152
|
|
153
|
+
def store_removed_constant(name, constant)
|
154
|
+
return if constant.is_a?(ClassConstant)
|
155
|
+
get_removed_constants << RemovedConstant.new(name, constant.dup)
|
156
|
+
end
|
157
|
+
|
125
158
|
def parent_constant?(klass, const_name)
|
126
159
|
modules = klass.to_s.split("::")[0..-2]
|
127
160
|
|
@@ -11,14 +11,13 @@ class Ree::LinkImportBuilder
|
|
11
11
|
# @param [Proc] proc
|
12
12
|
# @return [ArrayOf[String]] List of names of imported constants
|
13
13
|
def build(klass, package_name, object_name, proc)
|
14
|
-
|
14
|
+
const_list, removed_constants = Ree::ImportDsl.new.execute(klass, proc)
|
15
15
|
|
16
16
|
@packages_facade.load_package_object(package_name, object_name)
|
17
17
|
|
18
18
|
package = @packages_facade.get_package(package_name)
|
19
19
|
object = package.get_object(object_name)
|
20
|
-
|
21
|
-
|
20
|
+
|
22
21
|
const_list.each do |const_obj|
|
23
22
|
if object.klass.const_defined?(const_obj.name)
|
24
23
|
set_const(klass, object.klass.const_get(const_obj.name), const_obj)
|
@@ -29,6 +28,8 @@ class Ree::LinkImportBuilder
|
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
31
|
+
assign_removed_constants(klass, removed_constants)
|
32
|
+
|
32
33
|
const_list.map(&:name)
|
33
34
|
end
|
34
35
|
|
@@ -37,9 +38,8 @@ class Ree::LinkImportBuilder
|
|
37
38
|
# @param [Proc] proc
|
38
39
|
# @return [ArrayOf[String]] List of names of imported constants
|
39
40
|
def build_for_const(klass, source_const, proc)
|
40
|
-
|
41
|
+
const_list, removed_constants = Ree::ImportDsl.new.execute(klass, proc)
|
41
42
|
mod_const = Object.const_get(source_const.name.split("::").first)
|
42
|
-
const_list = [result] + result.constants
|
43
43
|
|
44
44
|
const_list.each do |const_obj|
|
45
45
|
if source_const.const_defined?(const_obj.name)
|
@@ -50,14 +50,28 @@ class Ree::LinkImportBuilder
|
|
50
50
|
raise Ree::Error.new("'#{const_obj.name}' is not found in '#{source_const}'")
|
51
51
|
end
|
52
52
|
end
|
53
|
+
|
54
|
+
assign_removed_constants(klass, removed_constants)
|
55
|
+
nil
|
53
56
|
end
|
54
57
|
|
55
58
|
private
|
56
59
|
|
60
|
+
def assign_removed_constants(klass, removed_constants)
|
61
|
+
removed_constants.each do |removed_const|
|
62
|
+
next if klass.const_defined?(removed_const.name)
|
63
|
+
klass.const_set(removed_const.name, removed_const.const)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
57
67
|
def set_const(target_klass, ref_class, const_obj)
|
58
68
|
if const_obj.get_as
|
59
69
|
target_klass.send(:remove_const, const_obj.get_as.name) rescue nil
|
60
70
|
target_klass.const_set(const_obj.get_as.name, ref_class)
|
71
|
+
|
72
|
+
if target_klass.const_get(const_obj.name).is_a?(Ree::ImportDsl::ClassConstant)
|
73
|
+
target_klass.send(:remove_const, const_obj.name)
|
74
|
+
end
|
61
75
|
else
|
62
76
|
target_klass.send(:remove_const, const_obj.name) rescue nil
|
63
77
|
target_klass.const_set(const_obj.name, ref_class)
|
data/lib/ree/dsl/object_dsl.rb
CHANGED
@@ -117,40 +117,6 @@ class Ree::ObjectDsl
|
|
117
117
|
@object.set_freeze(flag)
|
118
118
|
end
|
119
119
|
|
120
|
-
# @param [Nilor[Symbol]] code Global error code
|
121
|
-
# @param [Proc] proc Error DSL proc
|
122
|
-
def def_error(code = nil, &proc)
|
123
|
-
check_arg(code, :code, Symbol) if code
|
124
|
-
|
125
|
-
if !block_given?
|
126
|
-
raise_error("def_error should accept block with error class definition")
|
127
|
-
end
|
128
|
-
|
129
|
-
if code && !Ree.error_types.include?(code)
|
130
|
-
raise_error("Invalid error code :#{code}. Did you forget to setup it with Ree.add_error_types(*args)?")
|
131
|
-
end
|
132
|
-
|
133
|
-
class_name = begin
|
134
|
-
Ree::ErrorBuilder
|
135
|
-
.new(@packages_facade)
|
136
|
-
.build(
|
137
|
-
@object,
|
138
|
-
code,
|
139
|
-
&proc
|
140
|
-
)
|
141
|
-
rescue Ree::Error
|
142
|
-
raise_error("invalid def_error usage. Valid examples: def_error { InvalidDomainErr } or def_error(:validation) { EmailTakenErr['email taken'] }")
|
143
|
-
end
|
144
|
-
|
145
|
-
@object.add_const_list([class_name])
|
146
|
-
|
147
|
-
@object.errors.push(
|
148
|
-
Ree::ObjectError.new(
|
149
|
-
class_name
|
150
|
-
)
|
151
|
-
)
|
152
|
-
end
|
153
|
-
|
154
120
|
# @param [String] path Relative package file path ('accounts/entities/user')
|
155
121
|
# @param [Proc] proc Import constants proc
|
156
122
|
def link_file(path, import_proc = nil)
|
@@ -227,12 +193,14 @@ class Ree::ObjectDsl
|
|
227
193
|
raise Ree::Error.new("Mount as should be one of #{MOUNT_AS.inspect}", :invalid_dsl_usage)
|
228
194
|
end
|
229
195
|
|
230
|
-
|
231
|
-
File.
|
232
|
-
|
196
|
+
if !Ree.irb_mode?
|
197
|
+
object_name_from_path = if File.exist?(path)
|
198
|
+
File.basename(path, ".*").to_sym
|
199
|
+
end
|
233
200
|
|
234
|
-
|
235
|
-
|
201
|
+
if object_name_from_path && object_name != object_name_from_path
|
202
|
+
raise Ree::Error.new("Object name does not correspond to a file name (#{object_name}, #{object_name_from_path}.rb). Fix object name or rename object file", :invalid_dsl_usage)
|
203
|
+
end
|
236
204
|
end
|
237
205
|
|
238
206
|
class_name = klass.to_s
|
data/lib/ree/version.rb
CHANGED
data/lib/ree.rb
CHANGED
@@ -13,7 +13,6 @@ module Ree
|
|
13
13
|
autoload :Contracts, 'ree/contracts'
|
14
14
|
autoload :DomainError, 'ree/dsl/domain_error'
|
15
15
|
autoload :Error, 'ree/error'
|
16
|
-
autoload :ErrorBuilder, 'ree/dsl/error_builder'
|
17
16
|
autoload :ErrorDsl, 'ree/dsl/error_dsl'
|
18
17
|
autoload :FnDSL, 'ree/fn_dsl'
|
19
18
|
autoload :Gen, 'ree/gen'
|
@@ -262,18 +261,6 @@ module Ree
|
|
262
261
|
end
|
263
262
|
end
|
264
263
|
end
|
265
|
-
|
266
|
-
def error_types
|
267
|
-
@error_types ||= []
|
268
|
-
end
|
269
|
-
|
270
|
-
def add_error_types(*args)
|
271
|
-
args.each do |arg|
|
272
|
-
check_arg(arg, :error, Symbol)
|
273
|
-
end
|
274
|
-
|
275
|
-
@error_types = (error_types + args).uniq
|
276
|
-
end
|
277
264
|
end
|
278
265
|
end
|
279
266
|
|
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.31
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ruslan Gatiyatov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|
@@ -143,7 +143,6 @@ files:
|
|
143
143
|
- lib/ree/core/path_helper.rb
|
144
144
|
- lib/ree/dsl/build_package_dsl.rb
|
145
145
|
- lib/ree/dsl/domain_error.rb
|
146
|
-
- lib/ree/dsl/error_builder.rb
|
147
146
|
- lib/ree/dsl/error_dsl.rb
|
148
147
|
- lib/ree/dsl/import_dsl.rb
|
149
148
|
- lib/ree/dsl/link_import_builder.rb
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal = true
|
2
|
-
|
3
|
-
class Ree::ErrorBuilder
|
4
|
-
def initialize(packages_facade)
|
5
|
-
@packages_facade = packages_facade
|
6
|
-
end
|
7
|
-
|
8
|
-
def build(object, code, &proc)
|
9
|
-
result = Ree::ErrorDsl.new.execute(object.klass, &proc)
|
10
|
-
|
11
|
-
if result.is_a?(Ree::DomainError)
|
12
|
-
object.klass.send(:remove_const, result.name) rescue nil
|
13
|
-
result = Ree::ErrorDsl.new.execute(object.klass, &proc)
|
14
|
-
end
|
15
|
-
|
16
|
-
if !result.is_a?(Ree::ErrorDsl::ClassConstant)
|
17
|
-
raise Ree::Error.new("invalid def_error usage", :invalid_dsl_usage)
|
18
|
-
end
|
19
|
-
|
20
|
-
object.klass.send(:remove_const, result.name) rescue nil
|
21
|
-
|
22
|
-
object.klass.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1
|
23
|
-
class #{result.name} < Ree::DomainError
|
24
|
-
attr_reader :code, :extra_code, :error_code, :package_name, :object_name
|
25
|
-
|
26
|
-
def initialize(msg = nil, extra_code = nil)
|
27
|
-
@code = #{code.inspect}
|
28
|
-
@extra_code = extra_code
|
29
|
-
@error_code = :#{Ree::StringUtils.underscore(result.name)}
|
30
|
-
@package_name = :#{object.package_name}
|
31
|
-
@object_name = :#{object.name}
|
32
|
-
super(msg || #{result.message.inspect})
|
33
|
-
end
|
34
|
-
end
|
35
|
-
ruby_eval
|
36
|
-
|
37
|
-
result.name
|
38
|
-
end
|
39
|
-
end
|