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
- #custom_sql ⇒ Object protected
-
#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.
5 6 7 8 9 10 11 12 |
# File 'lib/active_admin/order_clause.rb', line 5 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.
3 4 5 |
# File 'lib/active_admin/order_clause.rb', line 3 def active_admin_config @active_admin_config end |
#field ⇒ Object (readonly)
Returns the value of attribute field.
3 4 5 |
# File 'lib/active_admin/order_clause.rb', line 3 def field @field end |
#order ⇒ Object (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
#apply(chain) ⇒ Object
18 19 20 |
# File 'lib/active_admin/order_clause.rb', line 18 def apply(chain) chain.reorder(Arel.sql sql) end |
#custom_sql ⇒ Object (protected)
41 42 43 44 45 |
# File 'lib/active_admin/order_clause.rb', line 41 def custom_sql if active_admin_config.ordering[@column].present? active_admin_config.ordering[@column].call(self) end end |
#sql ⇒ Object
35 36 37 |
# File 'lib/active_admin/order_clause.rb', line 35 def sql custom_sql || to_sql end |
#table ⇒ Object
26 27 28 |
# File 'lib/active_admin/order_clause.rb', line 26 def table active_admin_config.resource_column_names.include?(@column) ? active_admin_config.resource_table_name : nil end |
#table_column ⇒ Object
30 31 32 33 |
# File 'lib/active_admin/order_clause.rb', line 30 def table_column (@column =~ /\./) ? @column : [table, active_admin_config.resource_quoted_column_name(@column)].compact.join(".") end |
#to_sql ⇒ Object
22 23 24 |
# File 'lib/active_admin/order_clause.rb', line 22 def to_sql [table_column, @op, ' ', @order].compact.join end |
#valid? ⇒ Boolean
14 15 16 |
# File 'lib/active_admin/order_clause.rb', line 14 def valid? @field.present? && @order.present? end |