Sha256: 66b80857a0f7d8c21715e79fa3750f0fc03a4a76ea699d4fd93c1379187dac88

Contents?: true

Size: 517 Bytes

Versions: 2

Compression:

Stored size: 517 Bytes

Contents

# frozen_string_literal: true

module Sort
  module CurrentDirectionForHelper
    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

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

      params
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
actionset-0.4.2 lib/action_set/helpers/sort/current_direction_for_helper.rb
actionset-0.4.1 lib/action_set/helpers/sort/current_direction_for_helper.rb