diff --git a/app/models/zone.rb b/app/models/zone.rb index de9ddf1..462416e 100644 --- a/app/models/zone.rb +++ b/app/models/zone.rb @@ -12,6 +12,8 @@ # class Zone < ActiveRecord::Base + acts_as_searchable + belongs_to :user has_many :records, :dependent => :destroy diff --git a/app/views/search/results.html.haml b/app/views/search/results.html.haml new file mode 100644 index 0000000..9afadc8 --- /dev/null +++ b/app/views/search/results.html.haml @@ -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 ) \ No newline at end of file diff --git a/vendor/plugins/acts_as_searchable/.gitignore b/vendor/plugins/acts_as_searchable/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/vendor/plugins/acts_as_searchable/MIT-LICENSE b/vendor/plugins/acts_as_searchable/MIT-LICENSE new file mode 100644 index 0000000..9f13f83 --- /dev/null +++ b/vendor/plugins/acts_as_searchable/MIT-LICENSE @@ -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. diff --git a/vendor/plugins/acts_as_searchable/README b/vendor/plugins/acts_as_searchable/README new file mode 100644 index 0000000..dc297aa --- /dev/null +++ b/vendor/plugins/acts_as_searchable/README @@ -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.search('%ruby%') #=> [, , ] + +======= + +Copyright (c) 2008 Josh Clayton, released under the MIT license \ No newline at end of file diff --git a/vendor/plugins/acts_as_searchable/Rakefile b/vendor/plugins/acts_as_searchable/Rakefile new file mode 100644 index 0000000..d535a91 --- /dev/null +++ b/vendor/plugins/acts_as_searchable/Rakefile @@ -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 diff --git a/vendor/plugins/acts_as_searchable/init.rb b/vendor/plugins/acts_as_searchable/init.rb new file mode 100644 index 0000000..cf1dabe --- /dev/null +++ b/vendor/plugins/acts_as_searchable/init.rb @@ -0,0 +1,2 @@ +require 'acts_as_searchable' +ActiveRecord::Base.send(:include, Shooter::Acts::Searchable) diff --git a/vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb b/vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb new file mode 100644 index 0000000..ce77010 --- /dev/null +++ b/vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb @@ -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 \ No newline at end of file diff --git a/vendor/plugins/acts_as_searchable/tasks/acts_as_searchable_tasks.rake b/vendor/plugins/acts_as_searchable/tasks/acts_as_searchable_tasks.rake new file mode 100644 index 0000000..262a8df --- /dev/null +++ b/vendor/plugins/acts_as_searchable/tasks/acts_as_searchable_tasks.rake @@ -0,0 +1,4 @@ +# desc "Explaining what the task does" +# task :acts_as_searchable do +# # Task goes here +# end diff --git a/vendor/plugins/acts_as_searchable/test/acts_as_searchable_test.rb b/vendor/plugins/acts_as_searchable/test/acts_as_searchable_test.rb new file mode 100644 index 0000000..ceceb43 --- /dev/null +++ b/vendor/plugins/acts_as_searchable/test/acts_as_searchable_test.rb @@ -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