Skip to content

igor04/tire-multisort

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

tire sort extension

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages