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 (
commit 5f65bf2d24c5cb2d3039b2ba587aea40c143f366
tree 1e304e02352f88cc067de90d961f9a7e92f88e16
parent 7d5b736a355463d5ca9a0e528a128f11d7dde7fa
tree 1e304e02352f88cc067de90d961f9a7e92f88e16
parent 7d5b736a355463d5ca9a0e528a128f11d7dde7fa
| name | age | message | |
|---|---|---|---|
| |
MIT-LICENSE | Sat Apr 05 01:14:20 -0700 2008 | [technoweenie] |
| |
README | Sat Apr 05 01:14:20 -0700 2008 | [technoweenie] |
| |
Rakefile | Sat Apr 05 01:14:20 -0700 2008 | [technoweenie] |
| |
init.rb | Sat Apr 05 01:14:20 -0700 2008 | [technoweenie] |
| |
lib/ | Fri Aug 01 12:36:49 -0700 2008 | [towski] |
| |
spec/ | Fri Aug 01 12:36:49 -0700 2008 | [towski] |
| |
tasks/ | Sat Apr 05 01:14:20 -0700 2008 | [technoweenie] |
README
CanSearch
=========
Allows you create common named_scopes and chain them together with #search and
#search_for.
class Topic
belongs_to :forum
can_search do
scoped_by :forums
scoped_by :created, :scope => :date_range
end
# creates these two named scopes
# named_scope :by_forums, lambda { |f| {:conditions => {:forum_id => f}} }
# named_scope :created, lambda { |range| {:conditions => ...} }
end
Topic.search(:forum => 1) # Topic.by_forums(1)
Topic.search(:forums => [1,2]) # Topic.by_forums([1,2])
Topic.search(:created => (time1..time2)) # Topic.created(time1..time2)
Topic.search(:created => \
{:period => :daily, :start => Time.now}) # Topic.created(Time.now, Time.now + 1.day)
You can automatically paginate:
Topic.search :forum => 1, :page => params[:page]
You can also access the named_scope directly for custom #find or #calculate calls.
Topic.search_for(:forum => 1).sum(:hits)
Oh, and you can combine scopes:
Topic.search :forum => 1, :forums => [2, 3], :created => (time1..time2)
def can_search(&block)
self.search_scopes = CanSearch::SearchScopes.new(self, &block)
end
end
Copyright (c) 2008-* Rick Olson, released under the MIT license





