Sha256: f7e0902516738d8b38f3469ec7c9d10f3d36f27a284f1c96b4d14c812643f40f

Contents?: true

Size: 724 Bytes

Versions: 2

Compression:

Stored size: 724 Bytes

Contents

class Parelation::Criteria::Order < Parelation::Criteria

  require_relative "order/object"

  # @return [Regexp] The order format.
  #
  ORDER_FORMAT = /^order$/

  # @param param [String]
  # @return [TrueClass, FalseClass]
  #
  def self.match?(param)
    !!param.match(ORDER_FORMAT)
  end

  # Applies the specified orderings to {#chain}.
  #
  # @return [ActiveRecord::Relation] the modified chain.
  #
  def call
    orders.inject(chain) do |chain, order|
      chain.order(order.criteria)
    end
  end

  private

  # @return [Array<Parelation::Criteria::Order::Object>] an
  #   array of attributes to order.
  #
  def orders
    @orders ||= [value].flatten.map do |order|
      Object.new(order)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
parelation-1.0.0 lib/parelation/criteria/order.rb
parelation-0.2.0 lib/parelation/criteria/order.rb