65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/ransack/context.rb', line 65
def traverse(str, base = @base)
str ||= ''.freeze
if (segments = str.split(/_/)).size > 0
remainder = []
found_assoc = nil
while !found_assoc && segments.size > 0 do
assoc, klass = unpolymorphize_association(
segments.join('_'.freeze)
)
if found_assoc = get_association(assoc, base)
base = traverse(
remainder.join('_'.freeze), klass || found_assoc.klass
)
end
remainder.unshift segments.pop
end
raise UntraversableAssociationError,
"No association matches #{str}" unless found_assoc
end
klassify(base)
end
|