Module: Sort::CurrentDirectionForHelper

Included in:
ActionSet::Helpers::HelperMethods
Defined in:
lib/action_set/helpers/sort/current_direction_for_helper.rb

Instance Method Summary collapse

Instance Method Details

#current_paramsObject



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

def current_params
  return params.to_unsafe_hash if params.respond_to? :to_unsafe_hash

  params
end

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



5
6
7
8
9
10
11
12
# File 'lib/action_set/helpers/sort/current_direction_for_helper.rb', line 5

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

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

  direction
end