Class: QueryFilter::Rules::OrderBy

Inherits:
Scope
  • Object
show all
Defined in:
lib/query_filter/rules/order_by.rb

Constant Summary collapse

DIRECTIONS =
%w[asc desc].freeze

Constants inherited from Scope

Scope::VALIDATON_KEYS

Instance Attribute Summary

Attributes inherited from Scope

#keys

Instance Method Summary collapse

Methods inherited from Scope

#blank_validation?, #can_apply?, #endpoint, #initialize, #key

Constructor Details

This class inherits a constructor from QueryFilter::Rules::Scope

Instance Method Details

#direction_keyObject



15
16
17
# File 'lib/query_filter/rules/order_by.rb', line 15

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

#nameObject



7
8
9
# File 'lib/query_filter/rules/order_by.rb', line 7

def name
  'order_by'.freeze
end

#normalize_params(values) ⇒ Object



19
20
21
# File 'lib/query_filter/rules/order_by.rb', line 19

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

#valid?(params) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/query_filter/rules/order_by.rb', line 11

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