Class: Administrate::Order

Inherits:
Object
  • Object
show all
Defined in:
lib/administrate/order.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute = nil, direction = nil) ⇒ Order

Returns a new instance of Order.



3
4
5
6
# File 'lib/administrate/order.rb', line 3

def initialize(attribute = nil, direction = nil)
  @attribute = attribute
  @direction = direction || :asc
end

Instance Attribute Details

#directionObject (readonly)

Returns the value of attribute direction.



31
32
33
# File 'lib/administrate/order.rb', line 31

def direction
  @direction
end

Instance Method Details

#apply(relation) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/administrate/order.rb', line 8

def apply(relation)
  return order_by_association(relation) unless
    reflect_association(relation).nil?

  order = "#{relation.table_name}.#{attribute} #{direction}"

  return relation.reorder(order) if
    relation.columns_hash.keys.include?(attribute.to_s)

  relation
end

#order_params_for(attr) ⇒ Object



24
25
26
27
28
29
# File 'lib/administrate/order.rb', line 24

def order_params_for(attr)
  {
    order: attr,
    direction: reversed_direction_param_for(attr)
  }
end

#ordered_by?(attr) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/administrate/order.rb', line 20

def ordered_by?(attr)
  attr.to_s == attribute.to_s
end