Sha256: 86f6fdf4f06ac2c278891f8ed516bbed746e90515f2436ef27a7cf80b5af3493
Contents?: true
Size: 1.11 KB
Versions: 14
Compression:
Stored size: 1.11 KB
Contents
# frozen_string_literal: true module ActiveAdmin class OrderClause attr_reader :field, :order, :active_admin_config def initialize(active_admin_config, clause) clause =~ /^([\w\.]+)(->'\w+')?_(desc|asc)$/ @column = $1 @op = $2 @order = $3 @active_admin_config = active_admin_config @field = [@column, @op].compact.join end def valid? @field.present? && @order.present? end def apply(chain) chain.reorder(Arel.sql sql) end def to_sql [table_column, @op, " ", @order].compact.join end def table active_admin_config.resource_column_names.include?(@column) ? active_admin_config.resource_table_name : nil end def table_column if (@column.include?('.')) @column else [table, active_admin_config.resource_quoted_column_name(@column)].compact.join(".") end end def sql custom_sql || to_sql end protected def custom_sql if active_admin_config.ordering[@column].present? active_admin_config.ordering[@column].call(self) end end end end
Version data entries
14 entries across 14 versions & 1 rubygems