Module: Sort::CurrentDirectionForHelper

Includes:
Params::CurrentHelper, FormattingHelper
Included in:
NextDirectionForHelper
Defined in:
lib/action_set/helpers/sort/current_direction_for_helper.rb

Instance Method Summary collapse

Methods included from FormattingHelper

#ascending_str, #descending_str

Methods included from Params::CurrentHelper

#current_params

Instance Method Details

#current_sort_direction_for(attribute, format: :short) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/action_set/helpers/sort/current_direction_for_helper.rb', line 11

def current_sort_direction_for(attribute, format: :short)
  direction = current_params.dig(:sort, attribute).to_s.downcase

  return ascending_str(format) if direction.presence_in %w[asc ascending]
  return descending_str(format) if direction.presence_in %w[desc descending]

  direction
end