Class: Ree::ImportDsl
Defined Under Namespace
Classes: ClassConstant, RemovedConstant, UnlinkConstError
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ImportDsl.
4
5
6
|
# File 'lib/ree/dsl/import_dsl.rb', line 4
def initialize
setup_removed_constants
end
|
Instance Method Details
#cancel_patch_const_missing ⇒ Object
43
44
45
46
|
# File 'lib/ree/dsl/import_dsl.rb', line 43
def cancel_patch_const_missing
Module.define_method(:const_missing, @_original_const_missing)
@_original_const_missing = nil
end
|
#execute(klass, proc) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/ree/dsl/import_dsl.rb', line 8
def execute(klass, proc)
patch_const_missing
class_constant = self.class.instance_exec(&proc)
[
(class_constant),
get_removed_constants
]
rescue Ree::ImportDsl::UnlinkConstError => e
retry_after = remove_or_assign_const(klass, e.const)
retry if retry_after
rescue NoMethodError => e
if e.name == :& || e.name == :as
retry_after = remove_or_assign_const(klass, e.receiver)
retry if retry_after
else
raise e
end
rescue NameError => e
proc
.binding
.eval("#{e.name} = Ree::ImportDsl::ClassConstant.new('#{e.name}')")
retry
ensure
cancel_patch_const_missing
end
|
#patch_const_missing ⇒ Object
37
38
39
40
41
|
# File 'lib/ree/dsl/import_dsl.rb', line 37
def patch_const_missing
return if @_original_const_missing
@_original_const_missing = Module.instance_method(:const_missing)
Module.define_method(:const_missing){ |const_name| raise NameError.new("class not found #{const_name.to_s}", const_name) }
end
|