Class: ActiveAdmin::OrderClause

Inherits:
Object
  • Object
show all
Defined in:
lib/active_admin/order_clause.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(clause) ⇒ OrderClause

Returns a new instance of OrderClause.


5
6
7
8
9
10
11
12
# File 'lib/active_admin/order_clause.rb', line 5

def initialize(clause)
  clause =~ /^([\w\_\.]+)(->'\w+')?_(desc|asc)$/
  @column = $1
  @op = $2
  @order = $3

  @field = [@column, @op].compact.join
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field


3
4
5
# File 'lib/active_admin/order_clause.rb', line 3

def field
  @field
end

#orderObject (readonly)

Returns the value of attribute order


3
4
5
# File 'lib/active_admin/order_clause.rb', line 3

def order
  @order
end

Instance Method Details

#to_sql(active_admin_config) ⇒ Object


18
19
20
21
22
23
24
# File 'lib/active_admin/order_clause.rb', line 18

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

#valid?Boolean

Returns:

  • (Boolean)

14
15
16
# File 'lib/active_admin/order_clause.rb', line 14

def valid?
  @field.present? && @order.present?
end