Sha256: 185a652ed432636800a99ace940c7413ee20695b98c8dcd356f11413f6adc142
Contents?: true
Size: 1.22 KB
Versions: 12
Compression:
Stored size: 1.22 KB
Contents
module Lanes::Concerns # @see ClassMethods module SortingExpressions extend ActiveSupport::Concern module ClassMethods # Add a proc that will be called to add a sort expression to a query. # The proc should accept an arel query object and a single direction parameter, # which will be a symbol value of :asc or :desc # It must return a arel query with the sort applied # @param name [String] The name of the expression def export_sort( name, &block ) @sorting_expressions ||= {} @sorting_expressions[name.to_s] = block end def has_sorting_expression?(name) @sorting_expressions && @sorting_expressions[name] end def append_sort_to_query(query, field, dir) dir = :asc unless dir == :desc if @sorting_expressions && (block = @sorting_expressions[field]) block.call(query, dir) else query.order(field.gsub(/[^\w|^\.]/,'') + ' ' + ( ( :asc == dir ) ? 'ASC' : 'DESC' ) ) end end end end end
Version data entries
12 entries across 12 versions & 1 rubygems