Class: ActiveAdmin::OrderClause
- Inherits:
-
Object
- Object
- ActiveAdmin::OrderClause
- Defined in:
- lib/active_admin/order_clause.rb
Instance Attribute Summary collapse
-
#active_admin_config ⇒ Object
readonly
Returns the value of attribute active_admin_config.
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
Instance Method Summary collapse
- #apply(chain) ⇒ Object
-
#initialize(active_admin_config, clause) ⇒ OrderClause
constructor
A new instance of OrderClause.
- #sql ⇒ Object
- #table ⇒ Object
- #table_column ⇒ Object
- #to_sql ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(active_admin_config, clause) ⇒ OrderClause
Returns a new instance of OrderClause.
6 7 8 9 10 11 12 13 |
# File 'lib/active_admin/order_clause.rb', line 6 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 |
Instance Attribute Details
#active_admin_config ⇒ Object (readonly)
Returns the value of attribute active_admin_config.
4 5 6 |
# File 'lib/active_admin/order_clause.rb', line 4 def active_admin_config @active_admin_config end |
#field ⇒ Object (readonly)
Returns the value of attribute field.
4 5 6 |
# File 'lib/active_admin/order_clause.rb', line 4 def field @field end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
4 5 6 |
# File 'lib/active_admin/order_clause.rb', line 4 def order @order end |
Instance Method Details
#apply(chain) ⇒ Object
19 20 21 |
# File 'lib/active_admin/order_clause.rb', line 19 def apply(chain) chain.reorder(Arel.sql sql) end |
#sql ⇒ Object
36 37 38 |
# File 'lib/active_admin/order_clause.rb', line 36 def sql custom_sql || to_sql end |
#table ⇒ Object
27 28 29 |
# File 'lib/active_admin/order_clause.rb', line 27 def table active_admin_config.resource_column_names.include?(@column) ? active_admin_config.resource_table_name : nil end |
#table_column ⇒ Object
31 32 33 34 |
# File 'lib/active_admin/order_clause.rb', line 31 def table_column (@column =~ /\./) ? @column : [table, active_admin_config.resource_quoted_column_name(@column)].compact.join(".") end |
#to_sql ⇒ Object
23 24 25 |
# File 'lib/active_admin/order_clause.rb', line 23 def to_sql [table_column, @op, " ", @order].compact.join end |
#valid? ⇒ Boolean
15 16 17 |
# File 'lib/active_admin/order_clause.rb', line 15 def valid? @field.present? && @order.present? end |