4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/custom_fields/extensions/active_support.rb', line 4
def constantize
super
rescue NameError => e
if self =~ CustomFields::KLASS_REGEXP
base = ::Regexp.last_match(1).constantize
if base.with_custom_fields?
relation = base.relations.values.detect do |association|
association.options[:custom_fields_parent_klass] == true
end
if relation && parent_instance = relation.klass.find(::Regexp.last_match(2))
return parent_instance.klass_with_custom_fields(relation.inverse_of)
end
end
end
raise e
end
|