class Parelation::Criteria::Order::Object

Constants

DIRECTIONS

@return [Hash] the possible directions (asc, desc)

for database queries.

Attributes

order[R]

@return [String]

Public Class Methods

new(order) click to toggle source

@param order [String]

# File lib/parelation/criteria/order/object.rb, line 17
def initialize(order)
  @order = order
end

Public Instance Methods

criteria() click to toggle source

@return [Hash] returns criteria for {ActiveRecord::Relation}.

@example

{ created_at: :asc }
# File lib/parelation/criteria/order/object.rb, line 26
def criteria
  { field => direction }
end

Private Instance Methods

direction() click to toggle source

@return [Symbol, nil] the direction to order {#field},

either :asc or :desc.
# File lib/parelation/criteria/order/object.rb, line 41
def direction
  DIRECTIONS[parts.last]
end
field() click to toggle source

@return [String] the name of the field to perform the ordering on.

# File lib/parelation/criteria/order/object.rb, line 34
def field
  parts.first || ""
end
parts() click to toggle source

@return [Array<String, nil>] the criteria chunks (separated by :).

# File lib/parelation/criteria/order/object.rb, line 47
def parts
  @parts ||= order.split(":")
end