Sha256: cb523785511c3e971ce9b14651c86e14706c6d00277fe33a9138c570bd2dda00
Contents?: true
Size: 693 Bytes
Versions: 30
Compression:
Stored size: 693 Bytes
Contents
module ActiveAdmin class OrderClause attr_reader :field, :order def initialize(clause) clause =~ /^([\w\_\.]+)(->'\w+')?_(desc|asc)$/ @column = $1 @op = $2 @order = $3 @field = [@column, @op].compact.join end def valid? @field.present? && @order.present? end def to_sql(active_admin_config) table = active_admin_config.resource_column_names.include?(@column) ? active_admin_config.resource_table_name : nil table_column = (@column =~ /\./) ? @column : [table, active_admin_config.resource_quoted_column_name(@column)].compact.join(".") [table_column, @op, ' ', @order].compact.join end end end
Version data entries
30 entries across 30 versions & 6 rubygems