2
3
4
5
6
7
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
36
|
# File 'lib/ree/rspec_link_dsl.rb', line 2
def link(obj_name, import_proc = nil, as: nil, from: nil)
if obj_name.is_a?(Symbol)
obj = link_object(from, obj_name)
if obj.nil?
raise Ree::Error.new("object :#{obj_name} was not found for package :#{from}")
end
as ||= obj_name
define_method as do |*args, **kwargs, &proc|
if obj.object?
if obj.with_caller?
obj.klass.new.set_caller(self)
else
obj.klass.new
end
else
if obj.with_caller?
obj.klass.new.set_caller(self).call(*args, **kwargs, &proc)
else
obj.klass.new.call(*args, **kwargs, &proc)
end
end
end
elsif obj_name.is_a?(String)
const_list = link_file(from, obj_name, import_proc)
const_list.each do |const|
Object.const_set(const.name, self.const_get(const.name))
end
else
raise Ree::Error.new("Invalid link DSL usage. Args should be Hash or String")
end
end
|