class Ransack::Context
def traverse(str, base = @base)
def traverse(str, base = @base) str ||= ''.freeze segments = str.split(Constants::UNDERSCORE) unless segments.empty? remainder = [] found_assoc = nil until found_assoc || segments.empty? # Strip the _of_Model_type text from the association name, but hold # onto it in klass, for use as the next base assoc, klass = unpolymorphize_association( segments.join(Constants::UNDERSCORE) ) if found_assoc = get_association(assoc, base) base = traverse( remainder.join(Constants::UNDERSCORE), klass || found_assoc.klass ) end remainder.unshift segments.pop end unless found_assoc raise(UntraversableAssociationError, "No association matches #{str}") end end klassify(base) end