Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
MIT-LICENSE
README
init.rb

README

== Author
  Aaron Tian

== Contact
  Aaron2Ti@gmail.com

RecordsSequence
=============
  This plugin adds 'next/previous' methods to every ActiveRecord object.
  Using it you could easily find next/previous object accroding your requirements.


INSTALL
============
This plugin requires Rails 2.1 currently. Install easily by below command:
  ruby script/plugin install git://github.com/Aaron2Ti/records_sequence.git


USAGE
============
After installed, this plugin would mixin two methods(next and previous) to
every ActiveRecord object. So it's cool to do:

  class User < ActiveRecord::Base
  end

  foo = User.first
  bar = foo.next
  foo_neighbour = foo.previous  # returns nil if foo has no previous neighbour

  # The sequence's sorted column is defined by the new option :sorted_by,
  # which default is the 'id' column.
  foo = User.last
  pre_foo_sorted_by_id = foo.previous
  pre_foo_sorted_by_age = foo.previous(:sorted_by => 'age')

  # Also works fine with most other ActiveRecord's find options:
  foo = User.find 30
  foo.next(:conditions => ['age < ?', 20])
  foo.previous(:offset => 2)
  foo.next(:sorted_by => 'address', :order => 'name DESC, age')
  foo.previous( :sorted_by => 'age', :conditions => ['age < ?', 20],
                :order => 'name DESC, address', :offset => 2 )

Try Yourself!

Copyright (c) 2008 [Aaron Tian Email: Aaron2Ti@gmail.com],
released under the MIT license
Something went wrong with that request. Please try again.