github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

technoweenie / can_search

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 115
    • 5
  • Source
  • Commits
  • Network (5)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Click here to lend your support to: can_search and make a donation at www.pledgie.com ! Edit Pledgie Setup

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Build common named scopes automatically, and provide a simple way to merge them with a single #search call. — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Make bi-weekly use 1-15 and 16-end_of_month instead of 1-14 and 15-EOM 
tekkub (author)
Sun Dec 21 18:38:29 -0800 2008
technoweenie (committer)
Tue Dec 23 15:08:18 -0800 2008
commit  8f647f7631e4f195017ea112ee00c78627693e77
tree    8a4479213681a43fcf1a5a1634e7dd36f3283788
parent  5bcc52d0c3fe11b9f9a4a85fea0074f31d194545
can_search /
name age
history
message
file MIT-LICENSE Sat Apr 05 01:14:20 -0700 2008 initial commit (extraction from xtt) [technoweenie]
file README Sat Apr 05 01:14:20 -0700 2008 initial commit (extraction from xtt) [technoweenie]
file Rakefile Sat Apr 05 01:14:20 -0700 2008 initial commit (extraction from xtt) [technoweenie]
file init.rb Sat Apr 05 01:14:20 -0700 2008 initial commit (extraction from xtt) [technoweenie]
directory lib/ Tue Dec 23 15:08:18 -0800 2008 Make bi-weekly use 1-15 and 16-end_of_month ins... [tekkub]
directory spec/ Tue Dec 23 15:08:18 -0800 2008 Make bi-weekly use 1-15 and 16-end_of_month ins... [tekkub]
directory tasks/ Sat Apr 05 01:14:20 -0700 2008 initial commit (extraction from xtt) [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
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server