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



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

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

#nameObject



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

def name
  'order_by'
end

#normalize_params(values) ⇒ Object



22
23
24
# File 'lib/query_filter/rules/order_by.rb', line 22

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

#valid?(params) ⇒ Boolean

Returns:

  • (Boolean)


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

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