ree 1.0.28 → 1.0.29

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: e9d6451014359adf3959bb738c0af6d7b8409731861230587d9053ff12680a6c
4
- data.tar.gz: 58d5795a1a4053195b62cc8811528f05674f8d1f292d34b59ad50a0b6ac8599a
3
+ metadata.gz: 8a9bafffedbc153f633b682e9a7ecbce4ad38a75dbbb9a7436798a3766d57735
4
+ data.tar.gz: 4b2562f2fb06c0afc492cce67abf5044b160c900057b5c24e14eb76104bf9049
5
5
  SHA512:
6
- metadata.gz: '05780d456c3cada1a08ce6c5d9775054215121eb265305ab30a2b7a8b08b08528cbefc9912ea7ad6b4f46265832d5f266432f50788fdbb4fcd923d8e0025ef1d'
7
- data.tar.gz: bade40ae6f6123b55a04d0eaecb9af2c9ece3a3e7b05a0ecde0e9c5bb06344a6616033ce3e236a6fa2c7da4ef3f3c0514b4c53fce84ea19bb58f0e763a67b06d
6
+ metadata.gz: ad6eddfb2656ed64223758a2b3f9a720597ba9bbca3edddbccb7ca4b284770db9fa03e3b5c81cdd5d771858bfff3e2b39566820a993eaa4f02baf3e821e3f116
7
+ data.tar.gz: 14ecf3e59cdc5d0b3a78f9fcddc74ea39cc6fb7ff77bbe2a23d6a693cf4d98f47141cfb750b4d60f9a8e09c3971e070f25d70ccff11e76121187b80e603e1666
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree (1.0.28)
4
+ ree (1.0.29)
5
5
  commander (~> 4.6.0)
6
6
 
7
7
  GEM
@@ -4,12 +4,12 @@ class Ree::ImportDsl
4
4
  def execute(klass, proc)
5
5
  self.class.instance_exec(&proc)
6
6
  rescue Ree::ImportDsl::UnlinkConstError => e
7
- const_removed = remove_const(klass, e.const)
7
+ const_removed = remove_or_assign_const(klass, e.const)
8
8
 
9
9
  retry if const_removed
10
10
  rescue NoMethodError => e
11
11
  if e.name == :&
12
- const_removed = remove_const(klass, e.receiver)
12
+ const_removed = remove_or_assign_const(klass, e.receiver)
13
13
 
14
14
  if const_removed
15
15
  retry
@@ -29,7 +29,7 @@ class Ree::ImportDsl
29
29
 
30
30
  class UnlinkConstError < StandardError
31
31
  attr_reader :const
32
-
32
+
33
33
  def initialize(const)
34
34
  @const = const
35
35
  end
@@ -82,25 +82,63 @@ class Ree::ImportDsl
82
82
 
83
83
  private
84
84
 
85
- def remove_const(klass, constant)
86
- const_removed = false
85
+ def remove_or_assign_const(klass, constant)
86
+ retry_after = false
87
87
 
88
88
  klass.constants.each do |const_sym|
89
89
  const = klass.const_get(const_sym)
90
+ next if const.is_a?(ClassConstant)
90
91
 
91
92
  if constant.is_a?(Class) || constant.is_a?(Module)
92
93
  if (const.is_a?(Class) || const.is_a?(Module)) && const.name == constant.name
93
94
  klass.send(:remove_const, const_sym)
94
- const_removed = true
95
+ retry_after = true
95
96
  break
96
97
  end
97
98
  elsif const == constant
98
99
  klass.send(:remove_const, const_sym)
99
- const_removed = true
100
+ retry_after = true
100
101
  break
101
102
  end
102
103
  end
103
104
 
104
- const_removed
105
+ return true if retry_after
106
+
107
+ const_name = if constant.is_a?(String)
108
+ constant.to_sym
109
+ elsif constant.is_a?(Class) || constant.is_a?(Module)
110
+ constant.name
111
+ else
112
+ raise ArgumentError.new("unknown constant: #{constant.inspect}")
113
+ end
114
+
115
+ if parent_constant?(klass, const_name)
116
+ klass.const_set(const_name, ClassConstant.new(const_name.to_s))
117
+ retry_after = true
118
+ end
119
+
120
+ retry_after
121
+ end
122
+
123
+ private
124
+
125
+ def parent_constant?(klass, const_name)
126
+ modules = klass.to_s.split("::")[0..-2]
127
+
128
+ result = modules.each_with_index.any? do |mod, index|
129
+ mod = Object.const_get(modules[0..index].join("::"))
130
+ mod.constants.include?(const_name)
131
+ end
132
+
133
+ result || acnchestor_constant?(klass, const_name)
134
+ end
135
+
136
+ def acnchestor_constant?(klass, const_name)
137
+ return false if klass.ancestors.include?(klass) && klass.ancestors.size == 1
138
+
139
+ klass.ancestors.any? do |anchestor|
140
+ next if anchestor == klass
141
+ anchestor.constants.include?(const_name) || acnchestor_constant?(anchestor, const_name)
142
+ end
105
143
  end
106
144
  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.28"
4
+ VERSION = "1.0.29"
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.28
4
+ version: 1.0.29
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-04-05 00:00:00.000000000 Z
11
+ date: 2023-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander