Class: ActiveRecord::SearchService::Order

Inherits:
Object
  • Object
show all
Defined in:
app/services/active_record/search_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute, direction, order_str) ⇒ Order

Returns a new instance of Order.



65
66
67
68
69
# File 'app/services/active_record/search_service.rb', line 65

def initialize(attribute, direction, order_str)
  @attribute = attribute
  @direction = direction
  @order_str = order_str
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



63
64
65
# File 'app/services/active_record/search_service.rb', line 63

def attribute
  @attribute
end

#directionObject (readonly)

Returns the value of attribute direction.



63
64
65
# File 'app/services/active_record/search_service.rb', line 63

def direction
  @direction
end

#order_strObject (readonly)

Returns the value of attribute order_str.



63
64
65
# File 'app/services/active_record/search_service.rb', line 63

def order_str
  @order_str
end

Instance Method Details

#apply(relation) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'app/services/active_record/search_service.rb', line 71

def apply(relation)
  if order_str.present?
    relation.order(order_str)
  elsif attribute.present?
    relation.order(attribute => direction)
  else
    relation
  end
end