Sha256: 7d239389b52f736ca422596cac1b7fe4f496a1ffe0ecc63c3de48d2bbdf18669

Contents?: true

Size: 548 Bytes

Versions: 3

Compression:

Stored size: 548 Bytes

Contents

# frozen_string_literal: true

# Define order by filter rule
#
module QueryFilter
  module Rules
    class OrderBy < Scope
      DIRECTIONS = %w[asc desc].freeze

      def name
        'order_by'
      end

      def valid?(params)
        params[key].present? && DIRECTIONS.include?(params[direction_key].try(:downcase))
      end

      def direction_key
        @direction_key ||= (@options[:via] || 'sort_direction').to_sym
      end

      def normalize_params(values)
        [values[key], values[direction_key]]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
query_filter-0.2.3 lib/query_filter/rules/order_by.rb
query_filter-0.2.2 lib/query_filter/rules/order_by.rb
query_filter-0.2.0 lib/query_filter/rules/order_by.rb