public
Description: has_browser makes it possible to create simple, parameterized browser interfaces to your models. That is, given a set of parameters, return all the models that match.
Homepage: http://jamesgolick.com/
Clone URL: git://github.com/giraffesoft/has_browser.git
name age message
file .gitignore Mon May 19 12:30:37 -0700 2008 ignore pkg [James Golick]
file MIT-LICENSE Mon May 19 12:29:25 -0700 2008 fill in my name and gs inc's name in license file [James Golick]
file README Mon May 19 12:38:03 -0700 2008 update readme [James Golick]
file README.rdoc Mon May 19 12:38:03 -0700 2008 update readme [James Golick]
file Rakefile Mon May 19 12:29:45 -0700 2008 add stuff for uploading as a gem [James Golick]
file init.rb Tue May 13 11:10:02 -0700 2008 include assoc proxy methods module in AR module... [James Golick]
directory lib/ Sat Jun 21 07:19:30 -0700 2008 bump ver no [giraffesoft]
directory rails/ Sat Jun 21 07:09:54 -0700 2008 add rails/init.rb [giraffesoft]
directory tasks/ Sat Jun 21 07:19:02 -0700 2008 oops, add rails dir to gem [giraffesoft]
directory test/ Tue May 13 18:48:49 -0700 2008 dont fail with string param keys [James Golick]
README.rdoc

HasBrowser

====

has_browser makes it possible to create simple, parameterized browser interfaces to your models. That is, given a set of parameters, return all the models that match.

Usage

It’s a simple plugin, with a simple syntax. Using the canonical blog example, let’s imagine we want to create a browse interface to posts. We’d want the user to be able to browse by category, author, or tags, but not to be able to access any of the other finders on the Post model for obvious security reasons. To set up has_browser, we’d do something like this:

  has_browser :category, :tags, :author

Then, assuming the has_finders are already written, the posts can be browsed as follows:

  Post.browse(:category => 'Testing', :tags => 'activerecord', :author => 'james')

In that example, each of the finders requires an argument; has_browser also supports finders that don’t. As long as the argumentless finder is present in the browse hash, it will be called:

  has_browser :category, :tags, :author, :without_args => [:order_by_date, :order_by_number_of_comments]

  Post.browse(:category => 'Testing', :tags => 'activerecord', :author => 'james', :order_by_number_of_comments => 'true')

Browse can also be called from association_proxies. For a multi-blog platform, we could easily restrict browsing of posts to the current blog:

  @blog.posts.browse(:category => 'Testing', :tags => 'activerecord', :author => 'james', :order_by_number_of_comments => 'true')

Since has_browser returns the same proxy as has_finder, it is possible to further restrict the results of a browse by chaining finders after the browse call. With our blog, for example, we’d probably want to restrict browsing to published posts.

  @blog.posts.browse(:category => 'Testing', :tags => 'activerecord', :author => 'james', :order_by_number_of_comments => 'true').published

Note: It is not possible to chain finders before the browse call.

Finally, like has_finder, has_browser is compatible with will_paginate out of the box.

Releases & Development

has_browser will be released as a gem:

  $ sudo gem install has_browser

development will continue at {github}[http://github.com/giraffesoft/has_browser]

Credits & License

Copyright © 2008 {James Golick}[http://jamesgolick.com], {GiraffeSoft Inc.}[http://giraffesoft.ca], released under the {MIT License}[http://en.wikipedia.org/wiki/MIT_License]