Sha256: b566b10a670d7662a03cd36763d561f72cfb115d51172c4a4cc556c22e12374c
Contents?: true
Size: 1.04 KB
Versions: 12
Compression:
Stored size: 1.04 KB
Contents
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(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 (@column =~ /\./) ? @column : [table, active_admin_config.resource_quoted_column_name(@column)].compact.join(".") 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
12 entries across 12 versions & 2 rubygems