This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
Manifest | Wed Mar 18 18:45:52 -0700 2009 | |
| |
README.rdoc | Wed Mar 18 20:00:16 -0700 2009 | |
| |
Rakefile | Wed Mar 18 18:45:52 -0700 2009 | |
| |
TODO | Wed Mar 18 18:45:52 -0700 2009 | |
| |
benchmark/ | Sun Jun 14 05:57:16 -0700 2009 | |
| |
init.rb | Wed Mar 18 18:48:17 -0700 2009 | |
| |
inverse_sortable.gemspec | Wed Mar 18 19:05:10 -0700 2009 | |
| |
lib/ | Wed Mar 18 18:45:52 -0700 2009 | |
| |
test/ | Sun Jun 14 05:57:16 -0700 2009 |
README.rdoc
inverse_sortable
Sets negative timestamps on Active Record models for efficiently sort in reverse order.
Install
sudo gem install alvarobp-inverse_sortable --source http://gems.github.com
Add to environment.rb:
config.gem "alvarobp-inverse_sortable", :lib => "inverse_sortable"
Usage
As a very simple plugin, using it is simple. Just add an integer attribute called "created_at_inverse" to your model. Afterwards you can make that model inverse sortable, for example:
class Film < ActiveRecord::Base
acts_as_inverse_sortable
end
Therefore, you can get an inverse sorted array of Films with
Film.find(:all, :order => 'created_at_inverse')
Test
Just do
rake test
Benchmarks
I ran some benchmarks to see how efficient is this method. Well, most of the times benchmarks showed that this method is more efficient than "ORDER BY created_at DESC" as the table grows.
Just in case you want to run these benchmarks, you will need a mysql database (maybe other engines as well) and configure it at the top of benchmark/benchmark.rb file.







