Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Searching works, but currently only on zones. [#2 state:open]
- Loading branch information
keegan
committed
Jul 9, 2008
1 parent
f2c72a9
commit 7e388b0
Showing
10 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
%h1.underline= "Results for \"#{@search_parameters}\"" | ||
%br/ | ||
|
||
%h2.underline Zones | ||
|
||
- unless @zones.blank? | ||
- for zone in @zones do | ||
= link_to zone.name, zone_path( zone ) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2008 Josh Clayton | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
ActsAsSearchable | ||
================ | ||
|
||
ActsAsSearchable provides a simple way to search upon a model. It uses named_scope if available; otherwise, it will accept a block or return find(:all) with applicable conditions applied | ||
|
||
|
||
Example | ||
======= | ||
|
||
class Entry < ActiveRecord::Base | ||
acts_as_searchable :on => [:title, :body, "comments.body", "CONCAT(users.first_name, ' ', users.last_name)", "users.login"], :include => [:comments, :user] | ||
|
||
belongs_to :user | ||
has_many :comments | ||
end | ||
|
||
# within console | ||
Entry.search('Josh Clayton') #=> [<Entry>, <Entry>] | ||
Entry.search('%ruby%') #=> [<Entry>, <Entry>, <Entry>] | ||
|
||
======= | ||
|
||
Copyright (c) 2008 Josh Clayton, released under the MIT license |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'rake' | ||
require 'rake/testtask' | ||
require 'rake/rdoctask' | ||
|
||
desc 'Default: run unit tests.' | ||
task :default => :test | ||
|
||
desc 'Test the acts_as_searchable plugin.' | ||
Rake::TestTask.new(:test) do |t| | ||
t.libs << 'lib' | ||
t.pattern = 'test/**/*_test.rb' | ||
t.verbose = true | ||
end | ||
|
||
desc 'Generate documentation for the acts_as_searchable plugin.' | ||
Rake::RDocTask.new(:rdoc) do |rdoc| | ||
rdoc.rdoc_dir = 'rdoc' | ||
rdoc.title = 'ActsAsSearchable' | ||
rdoc.options << '--line-numbers' << '--inline-source' | ||
rdoc.rdoc_files.include('README') | ||
rdoc.rdoc_files.include('lib/**/*.rb') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'acts_as_searchable' | ||
ActiveRecord::Base.send(:include, Shooter::Acts::Searchable) |
47 changes: 47 additions & 0 deletions
47
vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module Shooter | ||
module Acts | ||
module Searchable | ||
def self.included(base) | ||
base.extend ClassMethods | ||
end | ||
|
||
module ClassMethods | ||
def acts_as_searchable(options = {}) | ||
unless searchable? | ||
cattr_accessor :searchable_attributes, :comparison_operator, :searchable_scope_options | ||
include InstanceMethods | ||
end | ||
|
||
self.searchable_attributes ||= [] | ||
self.searchable_attributes << (options.delete(:on) || []) | ||
self.searchable_attributes.flatten! | ||
self.comparison_operator = options.delete(:comparison) || :like | ||
self.searchable_scope_options ||= {} | ||
self.searchable_scope_options.update(options) {|k,v1,v2| k.to_sym == :include ? [v1 << v2].flatten.compact.uniq : v2 } | ||
end | ||
|
||
def searchable? | ||
self.included_modules.include?(InstanceMethods) | ||
end | ||
end | ||
|
||
module InstanceMethods | ||
def self.included(base) | ||
if base.respond_to?(:named_scope) | ||
base.named_scope :search, lambda { |query| base.searchable_scope_options.merge(:conditions => [base.searchable_attributes.map {|attribute| "#{"#{base.table_name}." unless attribute.to_s.include?(".")}#{attribute} #{base.comparison_operator.to_s.upcase} :query"}.join(" OR "), {:query => query}])} | ||
else | ||
base.extend ClassMethods | ||
end | ||
end | ||
|
||
module ClassMethods | ||
def search(query = nil, options = {}) | ||
with_scope(:find => self.searchable_scope_options.merge(:conditions => [self.searchable_attributes.map {|attribute| "#{"#{table_name}." unless attribute.to_s.include?(".")}#{attribute} #{self.comparison_operator.to_s.upcase} :query"}.join(" OR "), {:query => query}])) do | ||
block_given? ? yield(options) : find(:all, options) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
vendor/plugins/acts_as_searchable/tasks/acts_as_searchable_tasks.rake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# desc "Explaining what the task does" | ||
# task :acts_as_searchable do | ||
# # Task goes here | ||
# end |
8 changes: 8 additions & 0 deletions
8
vendor/plugins/acts_as_searchable/test/acts_as_searchable_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'test/unit' | ||
|
||
class ActsAsSearchableTest < Test::Unit::TestCase | ||
# Replace this with your real tests. | ||
def test_this_plugin | ||
flunk | ||
end | ||
end |