scoped_search 2.5.1 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/app/assets/stylesheets/scoped_search.scss +1 -4
- data/lib/scoped_search.rb +3 -16
- data/lib/scoped_search/compass.rb +3 -0
- data/lib/scoped_search/definition.rb +1 -2
- data/lib/scoped_search/query_builder.rb +33 -7
- data/lib/scoped_search/rails_helper.rb +4 -3
- data/lib/scoped_search/railtie.rb +8 -0
- data/lib/scoped_search/version.rb +1 -1
- data/spec/integration/relation_querying_spec.rb +21 -0
- metadata +22 -27
- data/.infinity_test +0 -8
data/Gemfile
CHANGED
data/LICENSE
CHANGED
@@ -18,12 +18,9 @@
|
|
18
18
|
font-weight: bold;
|
19
19
|
color: black;
|
20
20
|
display: inline-block;
|
21
|
-
width: 14px;
|
22
|
-
height: 14px;
|
23
21
|
margin-left: -6px;
|
24
|
-
margin-bottom: -5px;
|
25
|
-
text-shadow: 0 1px 0 rgba(255,255,255,1);
|
26
22
|
@include opacity(20);
|
23
|
+
vertical-align: middle;
|
27
24
|
&:hover,
|
28
25
|
&:focus {
|
29
26
|
text-decoration: none;
|
data/lib/scoped_search.rb
CHANGED
@@ -90,19 +90,6 @@ require 'scoped_search/auto_complete_builder'
|
|
90
90
|
ActiveRecord::Base.send(:extend, ScopedSearch::ClassMethods)
|
91
91
|
ActiveRecord::Base.send(:extend, ScopedSearch::BackwardsCompatibility)
|
92
92
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
#asset pipeline
|
99
|
-
if defined?(::Sprockets)
|
100
|
-
require 'scoped_search/engine'
|
101
|
-
end
|
102
|
-
|
103
|
-
#Compass
|
104
|
-
if defined?(::Compass)
|
105
|
-
base = File.join(File.dirname(__FILE__), '..')
|
106
|
-
styles = File.join(base, 'vendor', 'assets', 'stylesheets')
|
107
|
-
::Compass::Frameworks.register('scoped_search', :path => base, :stylesheets_directory => styles)
|
108
|
-
end
|
93
|
+
# Rails & Compass integration
|
94
|
+
require 'scoped_search/railtie' if defined?(::Rails)
|
95
|
+
require 'scoped_search/compass' if defined?(::Compass)
|
@@ -134,8 +134,7 @@ module ScopedSearch
|
|
134
134
|
|
135
135
|
def default_order(options)
|
136
136
|
return nil if options[:default_order].nil?
|
137
|
-
field_name = options[:on]
|
138
|
-
field_name = options[:rename] if options[:rename]
|
137
|
+
field_name = options[:rename].nil? ? options[:on] : options[:rename]
|
139
138
|
order = (options[:default_order].to_s.downcase.include?('desc')) ? "DESC" : "ASC"
|
140
139
|
return "#{field_name} #{order}"
|
141
140
|
end
|
@@ -59,9 +59,9 @@ module ScopedSearch
|
|
59
59
|
case notification
|
60
60
|
when :keycondition then keyconditions << value
|
61
61
|
when :keyparameter then keyparameters << value
|
62
|
-
when :parameter
|
63
|
-
when :include
|
64
|
-
when :joins
|
62
|
+
when :parameter then parameters << value
|
63
|
+
when :include then includes << value
|
64
|
+
when :joins then joins << value
|
65
65
|
else raise ScopedSearch::QueryNotSupported, "Cannot handle #{notification.inspect}: #{value.inspect}"
|
66
66
|
end
|
67
67
|
end
|
@@ -70,7 +70,7 @@ module ScopedSearch
|
|
70
70
|
case notification
|
71
71
|
when :parameter then parameters << value
|
72
72
|
when :include then includes << value
|
73
|
-
when :joins
|
73
|
+
when :joins then joins << value
|
74
74
|
else raise ScopedSearch::QueryNotSupported, "Cannot handle #{notification.inspect}: #{value.inspect}"
|
75
75
|
end
|
76
76
|
end
|
@@ -78,9 +78,9 @@ module ScopedSearch
|
|
78
78
|
# Build hash for ActiveRecord::Base#find for the named scope
|
79
79
|
find_attributes = {}
|
80
80
|
find_attributes[:conditions] = [sql] + keyparameters + parameters unless sql.blank?
|
81
|
-
find_attributes[:include] = includes.uniq
|
82
|
-
find_attributes[:joins] = joins.uniq
|
83
|
-
find_attributes[:order] = order
|
81
|
+
find_attributes[:include] = includes.uniq unless includes.empty?
|
82
|
+
find_attributes[:joins] = joins.uniq unless joins.empty?
|
83
|
+
find_attributes[:order] = order unless order.nil?
|
84
84
|
|
85
85
|
# p find_attributes # Uncomment for debugging
|
86
86
|
return find_attributes
|
@@ -220,6 +220,18 @@ module ScopedSearch
|
|
220
220
|
return datetime_test(field, operator, value, &block)
|
221
221
|
elsif field.set?
|
222
222
|
return set_test(field, operator, value, &block)
|
223
|
+
elsif field.definition.klass.reflections[field.relation].try(:macro) == :has_many
|
224
|
+
if field.definition.klass.reflections[field.relation].options.has_key?(:through)
|
225
|
+
value = value.to_i if field.offset
|
226
|
+
yield(:parameter, value)
|
227
|
+
join = has_many_through_join(field)
|
228
|
+
middle_table = field.definition.klass.reflections[field.relation].options[:through]
|
229
|
+
return "#{field.definition.klass.table_name}.id IN (SELECT #{field.reflection_keys(field.definition.klass.reflections[middle_table])[1]} FROM #{join} WHERE #{field.to_sql(operator, &block)} #{self.sql_operator(operator, field)} ? )"
|
230
|
+
else
|
231
|
+
value = value.to_i if field.offset
|
232
|
+
yield(:parameter, value)
|
233
|
+
return "#{field.definition.klass.table_name}.id IN (SELECT #{field.reflection_keys(field.definition.klass.reflections[field.relation])[1]} FROM #{field.klass.table_name} WHERE #{field.to_sql(operator, &block)} #{self.sql_operator(operator, field)} ? )"
|
234
|
+
end
|
223
235
|
else
|
224
236
|
value = value.to_i if field.offset
|
225
237
|
yield(:parameter, value)
|
@@ -227,6 +239,20 @@ module ScopedSearch
|
|
227
239
|
end
|
228
240
|
end
|
229
241
|
|
242
|
+
def has_many_through_join(field)
|
243
|
+
endpoint_table_name = field.klass.table_name
|
244
|
+
middle_table = field.definition.klass.reflections[field.relation].options[:through]
|
245
|
+
middle_table_name = field.definition.klass.reflections[middle_table].klass.table_name
|
246
|
+
|
247
|
+
<<-SQL
|
248
|
+
#{field.definition.klass.table_name}
|
249
|
+
INNER JOIN #{middle_table_name}
|
250
|
+
ON #{field.definition.klass.table_name}.id = #{middle_table_name}.#{field.reflection_keys(field.definition.klass.reflections[middle_table])[1]}
|
251
|
+
INNER JOIN #{endpoint_table_name}
|
252
|
+
ON #{middle_table_name}.#{field.reflection_keys(field.klass.reflections[middle_table])[1]} = #{endpoint_table_name}.id
|
253
|
+
SQL
|
254
|
+
end
|
255
|
+
|
230
256
|
# This module gets included into the Field class to add SQL generation.
|
231
257
|
module Field
|
232
258
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
module ScopedSearch
|
2
3
|
module RailsHelper
|
3
4
|
# Creates a link that alternates between ascending and descending.
|
@@ -188,8 +189,8 @@ module ScopedSearch
|
|
188
189
|
# auto_complete_method to respond the AJAX calls,
|
189
190
|
def auto_complete_field_tag(method, val,tag_options = {}, completion_options = {})
|
190
191
|
auto_completer_options = { :url => { :action => "auto_complete_#{method}" } }.update(completion_options)
|
191
|
-
|
192
|
-
text_field_tag(method, val,
|
192
|
+
options = tag_options.merge(:class => "auto_complete_input " << tag_options[:class].to_s)
|
193
|
+
text_field_tag(method, val,options) +
|
193
194
|
auto_complete_clear_value_button(method) +
|
194
195
|
content_tag("div", "", :id => "#{method}_auto_complete", :class => "auto_complete") +
|
195
196
|
auto_complete_field(method, auto_completer_options)
|
@@ -201,7 +202,7 @@ module ScopedSearch
|
|
201
202
|
# auto_complete_method to respond the JQuery calls,
|
202
203
|
def auto_complete_field_tag_jquery(method, val,tag_options = {}, completion_options = {})
|
203
204
|
url = url_for(:action => "auto_complete_#{method}", :filter => completion_options[:filter])
|
204
|
-
options = tag_options.merge(:class => "auto_complete_input")
|
205
|
+
options = tag_options.merge(:class => "auto_complete_input " << tag_options[:class].to_s)
|
205
206
|
text_field_tag(method, val, options) + auto_complete_clear_value_button(method) +
|
206
207
|
auto_complete_field_jquery(method, url, completion_options)
|
207
208
|
end
|
@@ -72,6 +72,7 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
72
72
|
ActiveRecord::Migration.create_table(:goos) { |t| t.string :foo }
|
73
73
|
class Goo < ActiveRecord::Base
|
74
74
|
has_many :jars
|
75
|
+
scoped_search :on => :foo
|
75
76
|
scoped_search :in => :jars, :on => :related
|
76
77
|
end
|
77
78
|
|
@@ -104,6 +105,22 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
104
105
|
it "should find all records for which none related bar records exist" do
|
105
106
|
::Goo.search_for('null? related').should have(1).items
|
106
107
|
end
|
108
|
+
|
109
|
+
it "should find all records which has relation with both related values" do
|
110
|
+
::Goo.search_for('related=bar AND related="another bar"').should have(1).items
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should find all records searching with both parent and child fields" do
|
114
|
+
::Goo.search_for('foo bar').should have(2).items
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should find the only record with two Jars" do
|
118
|
+
::Goo.search_for('foo bar "another bar"').should have(1).item
|
119
|
+
end
|
120
|
+
|
121
|
+
it "shouldn't find any records as there isn't an intersect" do
|
122
|
+
::Goo.search_for('too another').should have(0).items
|
123
|
+
end
|
107
124
|
|
108
125
|
end
|
109
126
|
|
@@ -252,6 +269,10 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
252
269
|
it "should find the two records that are related to a baz record" do
|
253
270
|
Koo.search_for('baz').should have(2).items
|
254
271
|
end
|
272
|
+
|
273
|
+
it "should find the two records that are related to a baz record" do
|
274
|
+
Koo.search_for('related=baz AND related="baz too!"').should have(1).items
|
275
|
+
end
|
255
276
|
end
|
256
277
|
end
|
257
278
|
end
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scoped_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.5.1
|
5
4
|
prerelease:
|
5
|
+
version: 2.6.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Amos Benari
|
@@ -11,56 +11,56 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-
|
14
|
+
date: 2013-06-17 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
|
-
|
18
|
-
requirement: !ruby/object:Gem::Requirement
|
19
|
-
none: false
|
17
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
18
|
requirements:
|
21
19
|
- - ! '>='
|
22
20
|
- !ruby/object:Gem::Version
|
23
21
|
version: 2.1.0
|
22
|
+
none: false
|
23
|
+
name: activerecord
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
|
27
|
-
none: false
|
26
|
+
requirement: !ruby/object:Gem::Requirement
|
28
27
|
requirements:
|
29
28
|
- - ! '>='
|
30
29
|
- !ruby/object:Gem::Version
|
31
30
|
version: 2.1.0
|
32
|
-
- !ruby/object:Gem::Dependency
|
33
|
-
name: rspec
|
34
|
-
requirement: !ruby/object:Gem::Requirement
|
35
31
|
none: false
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
34
|
requirements:
|
37
35
|
- - ~>
|
38
36
|
- !ruby/object:Gem::Version
|
39
37
|
version: '2.0'
|
38
|
+
none: false
|
39
|
+
name: rspec
|
40
40
|
type: :development
|
41
41
|
prerelease: false
|
42
|
-
|
43
|
-
none: false
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
44
43
|
requirements:
|
45
44
|
- - ~>
|
46
45
|
- !ruby/object:Gem::Version
|
47
46
|
version: '2.0'
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: rake
|
50
|
-
requirement: !ruby/object:Gem::Requirement
|
51
47
|
none: false
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
50
|
requirements:
|
53
51
|
- - ! '>='
|
54
52
|
- !ruby/object:Gem::Version
|
55
53
|
version: '0'
|
54
|
+
none: false
|
55
|
+
name: rake
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
|
59
|
-
none: false
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
60
59
|
requirements:
|
61
60
|
- - ! '>='
|
62
61
|
- !ruby/object:Gem::Version
|
63
62
|
version: '0'
|
63
|
+
none: false
|
64
64
|
description: ! " Scoped search makes it easy to search your ActiveRecord-based
|
65
65
|
models.\n \n It will create a named scope :search_for that can be called with
|
66
66
|
a query string. It will build an SQL query using\n the provided query string
|
@@ -82,7 +82,6 @@ extra_rdoc_files:
|
|
82
82
|
- README.rdoc
|
83
83
|
files:
|
84
84
|
- .gitignore
|
85
|
-
- .infinity_test
|
86
85
|
- .travis.yml
|
87
86
|
- Gemfile
|
88
87
|
- Gemfile.activerecord2
|
@@ -97,6 +96,7 @@ files:
|
|
97
96
|
- init.rb
|
98
97
|
- lib/scoped_search.rb
|
99
98
|
- lib/scoped_search/auto_complete_builder.rb
|
99
|
+
- lib/scoped_search/compass.rb
|
100
100
|
- lib/scoped_search/definition.rb
|
101
101
|
- lib/scoped_search/engine.rb
|
102
102
|
- lib/scoped_search/query_builder.rb
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/scoped_search/query_language/parser.rb
|
106
106
|
- lib/scoped_search/query_language/tokenizer.rb
|
107
107
|
- lib/scoped_search/rails_helper.rb
|
108
|
+
- lib/scoped_search/railtie.rb
|
108
109
|
- lib/scoped_search/version.rb
|
109
110
|
- scoped_search.gemspec
|
110
111
|
- spec/database.jruby.yml
|
@@ -140,26 +141,20 @@ rdoc_options:
|
|
140
141
|
require_paths:
|
141
142
|
- lib
|
142
143
|
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
-
none: false
|
144
144
|
requirements:
|
145
145
|
- - ! '>='
|
146
146
|
- !ruby/object:Gem::Version
|
147
147
|
version: '0'
|
148
|
-
segments:
|
149
|
-
- 0
|
150
|
-
hash: -3142613325770757127
|
151
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
148
|
none: false
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
150
|
requirements:
|
154
151
|
- - ! '>='
|
155
152
|
- !ruby/object:Gem::Version
|
156
153
|
version: '0'
|
157
|
-
|
158
|
-
- 0
|
159
|
-
hash: -3142613325770757127
|
154
|
+
none: false
|
160
155
|
requirements: []
|
161
156
|
rubyforge_project:
|
162
|
-
rubygems_version: 1.8.
|
157
|
+
rubygems_version: 1.8.23
|
163
158
|
signing_key:
|
164
159
|
specification_version: 3
|
165
160
|
summary: Easily search you ActiveRecord models with a simple query language using
|