Module: OrderQuery::Direction
Overview
Responsible for handling :asc and :desc
Constant Summary collapse
- DIRECTIONS =
[:asc, :desc].freeze
- DIRECTIONS_S =
DIRECTIONS.map { |d| d.to_s.freeze }.freeze
Instance Method Summary collapse
Instance Method Details
#all ⇒ Object
9 10 11 |
# File 'lib/order_query/direction.rb', line 9 def all DIRECTIONS end |
#parse!(direction) ⇒ :asc, :desc
22 23 24 25 26 27 28 29 30 |
# File 'lib/order_query/direction.rb', line 22 def parse!(direction) if direction.is_a?(Symbol) direction if DIRECTIONS.include?(direction) else direction = direction.to_s.downcase direction.to_sym if DIRECTIONS_S.include?(direction) end or raise ArgumentError.new("sort direction must be in #{all.map(&:inspect).join(', ')}, is #{direction.inspect}") end |
#reverse(direction) ⇒ :asc, :desc
15 16 17 |
# File 'lib/order_query/direction.rb', line 15 def reverse(direction) all[(all.index(direction) + 1) % 2].to_sym end |