Tire Multisort
multi_sort
extended tire sort
with some abilities
Installation
Add this line to your application's Gemfile:
gem 'tire-multisort'
And then execute:
$ bundle
Or install it yourself as:
$ gem install tire-multisort
Usage
multi_sort sort, order do
by_default :premium
by :date
by :name, :title
by :rating, :subject_rating
by :relevance, :_score
by :category, :category_name
by :distance, :_geo_distance, location: "test", unit: 'mi'
by :premium, :premium, :desc
by_collection :category, [:category, :name]
by_collection :premium, [:premium, :relevance, :name]
end
Checkpoints
multi sort
- acceptsort
argument as stringname,rating,date
which will be translated to propper sorting fieldauto order
# multi_sort
by :date
# sort
by :date, order
predefined order
- using predefined order insteadorder
parameter
# multi_sort
by :date, :asc
by :date, invert(order) # helper method (useful for some combination with using `collections`)
# sort
by :date, :asc
by :date, (order == :asc ? :desc : :asc)
auto check
- run sort just fromcollection
,default
or fromsort
param
# multi_sort
by :date
# sort
if sort == :date
by :date, order
end
aliasing
# multi_sort
by :name, :title
# sort
if sort == :name
by :title, order
end
collections
- group fiew sort fields to sort collection
# multi_sort
by_collection :category, [:category, :name]
# sort
if sort == :category
by :category, order
by :name, order
end
default
- is used if passed sort param is incorrect or missed
by_default :premium
Contributing
- Fork it ( http://github.com/igor04/tire-multisort/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request