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
giraffesoft (author)
Sat Jun 21 07:19:30 -0700 2008
commit  13786b10e7c4a7d96f095f48aea6bd5af1885802
tree    1801b7e8f087a8e6181c6f35431644f04a770759
parent  d690f44e32a0a24f287931de0831c3ca14d26be4
has_browser / README
100644 45 lines (23 sloc) 2.405 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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 (c) 2008 {James Golick}[http://jamesgolick.com], {GiraffeSoft Inc.}[http://giraffesoft.ca], released under the {MIT License}[http://en.wikipedia.org/wiki/MIT_License]