4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/json_api_client/utils.rb', line 4
def self.compute_type(klass, type_name)
return type_name.constantize if type_name.match(/^::/)
candidates = []
klass.name.scan(/::|$/) { candidates.unshift "#{$`}::#{type_name}" }
candidates << type_name
candidates.each do |candidate|
begin
constant = candidate.constantize
return constant if candidate == constant.to_s
rescue NameError => e
raise e unless e.instance_of?(NameError)
end
end
raise NameError, "uninitialized constant #{candidates.first}"
end
|