search_scope 0.1.8 → 0.1.9
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/README +0 -3
- data/Rakefile +1 -1
- data/lib/search_scope.rb +17 -0
- data/search_scope.gemspec +2 -2
- metadata +2 -2
data/README
CHANGED
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('search_scope', '0.1.
|
5
|
+
Echoe.new('search_scope', '0.1.9') do |p|
|
6
6
|
p.description = "Simplify searching a model by defining custom named_scopes."
|
7
7
|
p.project = 'search-scope'
|
8
8
|
p.url = "http://rubyforge.org/projects/search-scope"
|
data/lib/search_scope.rb
CHANGED
@@ -111,6 +111,10 @@ module SearchScope
|
|
111
111
|
scopes
|
112
112
|
end
|
113
113
|
|
114
|
+
def get_named_scope_from_object(object, scope, *args)
|
115
|
+
scope = object.send(scope, *args)
|
116
|
+
end
|
117
|
+
|
114
118
|
def get_search_scope_from_object(object, scope, *args)
|
115
119
|
scope_name = "search_#{scope}".intern
|
116
120
|
scope = object.send(scope_name, *args)
|
@@ -163,6 +167,9 @@ module SearchScope
|
|
163
167
|
raise "unsupported type for search scope: #{scope.inspect}"
|
164
168
|
end
|
165
169
|
end
|
170
|
+
#TODO add filter_scopes here as well
|
171
|
+
aggregate_scope = aggregate_named_scope(aggregate_scope, params)
|
172
|
+
|
166
173
|
unless params[:quick_search].blank?
|
167
174
|
aggregate_scope = aggregate_scope.scoped quick_search_scope_options(params[:quick_search], params[:split_terms])
|
168
175
|
end
|
@@ -177,6 +184,16 @@ module SearchScope
|
|
177
184
|
aggregate_scope.find(:all)
|
178
185
|
end
|
179
186
|
end
|
187
|
+
|
188
|
+
#you supply an additional :named_scope. Just one for now. And it can't take a param yet.
|
189
|
+
#(to enable this, we'd have to have something like :named_scope => [:scope_name, arg1, arg2]) at which point I'd rather just use filters
|
190
|
+
#TODO I may want to add the ability to pass a comma separated string.. but not yet
|
191
|
+
def aggregate_named_scope(aggregate_scope, params)
|
192
|
+
named_scope = params.delete :named_scope
|
193
|
+
return aggregate_scope if named_scope.blank?
|
194
|
+
raise "the :named_scope param currently only supports a single symbol and no args." unless named_scope.is_a? Symbol
|
195
|
+
aggregate_scope = get_named_scope_from_object(aggregate_scope, named_scope)
|
196
|
+
end
|
180
197
|
|
181
198
|
#this is for use with will_paginate
|
182
199
|
def paginate_search(params={})
|
data/search_scope.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{search_scope}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.9"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Ryan Owens"]
|
9
|
-
s.date = %q{2009-01-
|
9
|
+
s.date = %q{2009-01-23}
|
10
10
|
s.description = %q{Simplify searching a model by defining custom named_scopes.}
|
11
11
|
s.email = %q{ryan@infoether.com}
|
12
12
|
s.extra_rdoc_files = ["CHANGELOG", "lib/search_scope.rb", "README"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: search_scope
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Owens
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-01-
|
12
|
+
date: 2009-01-23 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|