Sha256: 45310323e38e8e460b731100c078cc6032ac53ab66a868ea8b91c576bbf921b0
Contents?: true
Size: 1.08 KB
Versions: 19
Compression:
Stored size: 1.08 KB
Contents
module Searchlogic module NamedScopes # Handles dynamically creating named scopes for associations. module AssociationOrdering private def method_missing(name, *args, &block) if details = association_ordering_condition_details(name) create_association_ordering_condition(details[:association], details[:order_as], details[:column], args) send(name, *args) else super end end def association_ordering_condition_details(name) associations = reflect_on_all_associations.collect { |assoc| assoc.name } if !local_condition?(name) && name.to_s =~ /^(ascend|descend)_by_(#{associations.join("|")})_(\w+)$/ {:order_as => $1, :association => $2, :column => $3} end end def create_association_ordering_condition(association_name, order_as, column, args) named_scope("#{order_as}_by_#{association_name}_#{column}", association_condition_options(association_name, "#{order_as}_by_#{column}", args)) end end end end
Version data entries
19 entries across 19 versions & 4 rubygems