meta_search 0.3.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,21 +0,0 @@
1
- require 'meta_search'
2
-
3
- module MetaSearch
4
- class Railtie < Rails::Railtie #:nodoc:
5
- railtie_name :meta_search
6
-
7
- initializer "meta_search.active_record" do |app|
8
- if defined? ::ActiveRecord
9
- require 'meta_search/searches/active_record'
10
- MetaSearch::Searches::ActiveRecord.enable!
11
- end
12
- end
13
-
14
- initializer "meta_search.action_view" do |app|
15
- if defined? ::ActionView
16
- require 'meta_search/helpers/action_view'
17
- MetaSearch::Helpers::FormBuilder.enable!
18
- end
19
- end
20
- end
21
- end
@@ -1,46 +0,0 @@
1
- require 'meta_search/builder'
2
-
3
- module MetaSearch
4
- module Searches
5
- module Base
6
- # Prepares the search to run against your model. Returns an instance of
7
- # MetaSearch::Builder, which behaves pretty much like an ActiveRecord::Relation,
8
- # in that it doesn't actually query the database until you do something that
9
- # requires it to do so.
10
- def search(opts = {})
11
- opts ||= {} # to catch nil params
12
- search_options = opts.delete(:search_options) || {}
13
- builder = MetaSearch::Builder.new(self, search_options)
14
- builder.build(opts)
15
- end
16
-
17
- private
18
-
19
- # Excludes model attributes from searchability. This means that searches can't be created against
20
- # these columns, whether the search is based on this model, or the model's attributes are being
21
- # searched by association from another model. If a Comment <tt>belongs_to :article</tt> but declares
22
- # <tt>metasearch_exclude_attr :user_id</tt> then <tt>Comment.search</tt> won't accept parameters
23
- # like <tt>:user_id_equals</tt>, nor will an Article.search accept the parameter
24
- # <tt>:comments_user_id_equals</tt>.
25
- def metasearch_exclude_attr(*args)
26
- args.each do |attr|
27
- attr = attr.to_s
28
- raise(ArgumentError, "No persisted attribute (column) named #{attr} in #{self}") unless self.columns_hash.has_key?(attr)
29
- self._metasearch_exclude_attributes = (self._metasearch_exclude_attributes + [attr]).uniq
30
- end
31
- end
32
-
33
- # Excludes model associations from searchability. This mean that searches can't be created against
34
- # these associations. An article that <tt>has_many :comments</tt> but excludes comments from
35
- # searching by declaring <tt>metasearch_exclude_assoc :comments</tt> won't make any of the
36
- # <tt>comments_*</tt> methods available.
37
- def metasearch_exclude_assoc(*args)
38
- args.each do |assoc|
39
- assoc = assoc.to_s
40
- raise(ArgumentError, "No such association #{assoc} in #{self}") unless self.reflect_on_all_associations.map {|a| a.name.to_s}.include?(assoc)
41
- self._metasearch_exclude_associations = (self._metasearch_exclude_associations + [assoc]).uniq
42
- end
43
- end
44
- end
45
- end
46
- end