0.0
No commit activity in last 3 years
No release in over 3 years
multi_sort extended tire sort with some abilities
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

Tire Multisort

Gem Version Code Climate Test Coverage Build Status

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 - accept sort argument as string name,rating,date which will be translated to propper sorting field

  • auto order

      # multi_sort
      by :date
      # sort
      by :date, order
  • predefined order - using predefined order instead order 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 from collection, default or from sort 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

  1. Fork it ( http://github.com/igor04/tire-multisort/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request