ree 1.0.29 → 1.0.30
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/dsl/import_dsl.rb +45 -12
- data/lib/ree/dsl/link_import_builder.rb +19 -5
- 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: c26bd9f765b493214449328b06c723150c4d64a1a6198836ccdd3e92d6c38ed2
|
4
|
+
data.tar.gz: bec255f8119ff87b049000bb758e157d18507568d636fa4e19e6bbe363b9e4f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 312e40978d8bec156f2a8bce86a84083045a8034f5436ef7f53c506806ef0044b4c29ca2a09b0233614d20f5198ac6c0babdf2484852816f0d8a3787b4e54461
|
7
|
+
data.tar.gz: b8c81dc9707038944f00ddc38ab4a3f269597630b1a05923df292244f4e12d5d9a8e2ceb3651f3f09003a9ed2a1bfd1eb31d47507a6cb6d05bb5a43ad717d2c1
|
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/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.30
|
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-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|