Records Sequence plugin

Plugin details

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

Websitehttp://aaron2ti.blogspot.com/2008/06/plugin-released-recordssequence.html Repositorygit://github.com/Aaron2Ti/records_sequence.git Author Aaron Tian Tags navigate, active LicenseMIT

Documentation

Install the plugin:
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 )

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, about 1 month ago