meta_search 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitmodules +6 -0
- data/Gemfile +7 -0
- data/README.rdoc +165 -26
- data/Rakefile +18 -5
- data/VERSION +1 -1
- data/lib/meta_search.rb +28 -18
- data/lib/meta_search/builder.rb +178 -125
- data/lib/meta_search/exceptions.rb +1 -0
- data/lib/meta_search/helpers.rb +3 -0
- data/lib/meta_search/helpers/form_builder.rb +152 -0
- data/lib/meta_search/helpers/form_helper.rb +20 -0
- data/lib/meta_search/helpers/url_helper.rb +39 -0
- data/lib/meta_search/method.rb +129 -0
- data/lib/meta_search/model_compatibility.rb +36 -2
- data/lib/meta_search/searches/active_record.rb +88 -11
- data/lib/meta_search/utility.rb +1 -1
- data/lib/meta_search/where.rb +119 -61
- data/meta_search.gemspec +33 -13
- data/test/fixtures/company.rb +15 -2
- data/test/fixtures/data_types.yml +3 -3
- data/test/fixtures/developer.rb +3 -0
- data/test/helper.rb +10 -6
- data/test/test_search.rb +502 -288
- data/test/test_view_helpers.rb +152 -53
- metadata +82 -15
- data/lib/meta_search/helpers/action_view.rb +0 -168
- data/lib/meta_search/railtie.rb +0 -21
- data/lib/meta_search/searches/base.rb +0 -46
data/lib/meta_search/railtie.rb
DELETED
@@ -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
|