module Trailblazer::Finder::Helpers::Sorting
Public Instance Methods
new_sort_params_for(attribute)
click to toggle source
# File lib/trailblazer/finder/helpers/sorting.rb, line 48 def new_sort_params_for(attribute) params.merge! sort: "#{attribute} #{sort_direction_for(attribute)}" end
remove_sort_params_for(attribute)
click to toggle source
# File lib/trailblazer/finder/helpers/sorting.rb, line 40 def remove_sort_params_for(attribute) return unless sorting.include?(attribute.to_s) sort = sorting.gsub(/#{attribute} #{sort_direction_for(attribute)}/, "").split(",") sort.delete_if(&:blank?) params.merge! sort: sort.join(",") end
reverse_sort_direction_for(attribute)
click to toggle source
# File lib/trailblazer/finder/helpers/sorting.rb, line 24 def reverse_sort_direction_for(attribute) return "desc" if (!sorting.nil? && sorting.include?("#{attribute} asc")) || @find.config[:sorting][attribute.to_sym] == :asc "asc" end
sort?(attribute)
click to toggle source
# File lib/trailblazer/finder/helpers/sorting.rb, line 14 def sort?(attribute) sorting.include?(attribute.to_s) end
sort_direction_for(attribute)
click to toggle source
# File lib/trailblazer/finder/helpers/sorting.rb, line 18 def sort_direction_for(attribute) return "asc" if (!sorting.nil? && sorting.include?("#{attribute} asc")) || @find.config[:sorting][attribute.to_sym] == :asc "desc" end
sort_params_for(attribute)
click to toggle source
# File lib/trailblazer/finder/helpers/sorting.rb, line 30 def sort_params_for(attribute) if sorting.nil? params.merge! sort: "#{attribute} #{sort_direction_for(attribute)}" elsif sorting.include?(attribute.to_s) params.merge! sort: sorting.gsub(/#{attribute} #{sort_direction_for(attribute)}/, "#{attribute} #{reverse_sort_direction_for(attribute)}") else params.merge! sort: "#{sorting}, #{attribute} #{sort_direction_for(attribute)}" end end
sorting()
click to toggle source
# File lib/trailblazer/finder/helpers/sorting.rb, line 7 def sorting return if @errors.any? return if @find.sorting.empty? @sorting ||= Utils::Hash.remove_keys_from_hash(@find.sorting, [:handler]).map { |r| r.join(" ") }.join(", ") end