scoped_search 4.1.6 → 4.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +14 -1
- data/CHANGELOG.rdoc +6 -0
- data/Gemfile.activerecord52 +17 -0
- data/Gemfile.activerecord52_with_activesupport52 +18 -0
- data/lib/scoped_search/auto_complete_builder.rb +1 -0
- data/lib/scoped_search/definition.rb +11 -1
- data/lib/scoped_search/version.rb +1 -1
- data/spec/integration/auto_complete_spec.rb +26 -1
- data/spec/integration/key_value_querying_spec.rb +15 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d5d5ddd90a25434d39644b46bf7ff531a4c3b9f
|
4
|
+
data.tar.gz: c6f84e3fa52f86b25d03b0ec6a0cb61fb0be79e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e798cdc07468120499ae613122e4a96d6e300998cf3868af27e4df65204af23a28aed861cb3144a7b7bdf44097b5024684b91d0db1a9becdb0397c73d0e39cc6
|
7
|
+
data.tar.gz: 0da17cd812a2ca5f2802e3cff5835317117426530707d6af6dc1d1d093a9efac13378d1d781b8a1512fd86ca6ab969ef6fe10be6ac6e30356ec988a040cd49d4
|
data/.travis.yml
CHANGED
@@ -14,8 +14,10 @@ rvm:
|
|
14
14
|
- "2.0"
|
15
15
|
- "2.1"
|
16
16
|
- "2.2.2"
|
17
|
-
- "2.3.
|
17
|
+
- "2.3.7"
|
18
18
|
- "2.4.0"
|
19
|
+
- "2.5.0"
|
20
|
+
- "2.6.0"
|
19
21
|
- ruby-head
|
20
22
|
- jruby-19mode
|
21
23
|
- jruby-head
|
@@ -24,6 +26,8 @@ gemfile:
|
|
24
26
|
- Gemfile.activerecord42
|
25
27
|
- Gemfile.activerecord50
|
26
28
|
- Gemfile.activerecord51
|
29
|
+
- Gemfile.activerecord52
|
30
|
+
- Gemfile.activerecord52_with_activesupport52
|
27
31
|
|
28
32
|
matrix:
|
29
33
|
allow_failures:
|
@@ -39,3 +43,12 @@ matrix:
|
|
39
43
|
gemfile: Gemfile.activerecord51
|
40
44
|
- rvm: "2.1"
|
41
45
|
gemfile: Gemfile.activerecord51
|
46
|
+
- rvm: "2.0"
|
47
|
+
gemfile: Gemfile.activerecord52
|
48
|
+
- rvm: "2.1"
|
49
|
+
gemfile: Gemfile.activerecord52
|
50
|
+
- rvm: "2.0"
|
51
|
+
gemfile: Gemfile.activerecord52_with_activesupport52
|
52
|
+
- rvm: "2.1"
|
53
|
+
gemfile: Gemfile.activerecord52_with_activesupport52
|
54
|
+
|
data/CHANGELOG.rdoc
CHANGED
@@ -8,6 +8,12 @@ Please add an entry to the "Unreleased changes" section in your pull requests.
|
|
8
8
|
|
9
9
|
- Nothing yet
|
10
10
|
|
11
|
+
=== Version 4.1.7
|
12
|
+
|
13
|
+
- When Active Support is available, we parse time respecting current time zone
|
14
|
+
- Allow dots in rename definitions
|
15
|
+
- Accept extra value_filter in `complete_for`
|
16
|
+
|
11
17
|
=== Version 4.1.6
|
12
18
|
|
13
19
|
- Support for UUID columns on PostgreSQL (#184)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
gemspec
|
3
|
+
|
4
|
+
gem 'actionview', '~> 5.2.0'
|
5
|
+
gem 'activerecord', '~> 5.2.0'
|
6
|
+
|
7
|
+
platforms :jruby do
|
8
|
+
gem 'activerecord-jdbcsqlite3-adapter'
|
9
|
+
gem 'activerecord-jdbcmysql-adapter'
|
10
|
+
gem 'activerecord-jdbcpostgresql-adapter'
|
11
|
+
end
|
12
|
+
|
13
|
+
platforms :ruby do
|
14
|
+
gem 'sqlite3', '~> 1.3.6'
|
15
|
+
gem 'mysql2', '>= 0.3.18', '< 0.5'
|
16
|
+
gem 'pg', '~> 0.18'
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
gemspec
|
3
|
+
|
4
|
+
gem 'actionview', '~> 5.2.0'
|
5
|
+
gem 'activerecord', '~> 5.2.0'
|
6
|
+
gem 'activesupport', '~> 5.2.0'
|
7
|
+
|
8
|
+
platforms :jruby do
|
9
|
+
gem 'activerecord-jdbcsqlite3-adapter'
|
10
|
+
gem 'activerecord-jdbcmysql-adapter'
|
11
|
+
gem 'activerecord-jdbcpostgresql-adapter'
|
12
|
+
end
|
13
|
+
|
14
|
+
platforms :ruby do
|
15
|
+
gem 'sqlite3', '~> 1.3.6'
|
16
|
+
gem 'mysql2', '>= 0.3.18', '< 0.5'
|
17
|
+
gem 'pg', '~> 0.18'
|
18
|
+
end
|
@@ -208,6 +208,7 @@ module ScopedSearch
|
|
208
208
|
def complete_value_from_db(field, special_values, val)
|
209
209
|
count = 20 - special_values.count
|
210
210
|
completer_scope(field)
|
211
|
+
.where(@options[:value_filter])
|
211
212
|
.where(value_conditions(field.quoted_field, val))
|
212
213
|
.select(field.quoted_field)
|
213
214
|
.limit(count)
|
@@ -238,6 +238,9 @@ module ScopedSearch
|
|
238
238
|
if field.nil?
|
239
239
|
dotted = name.to_s.split('.')[0]
|
240
240
|
field = fields[dotted.to_sym] unless dotted.blank?
|
241
|
+
if field && field.key_relation.nil?
|
242
|
+
return nil
|
243
|
+
end
|
241
244
|
end
|
242
245
|
field
|
243
246
|
end
|
@@ -275,6 +278,8 @@ module ScopedSearch
|
|
275
278
|
# Try to parse a string as a datetime.
|
276
279
|
# Supported formats are Today, Yesterday, Sunday, '1 day ago', '2 hours ago', '3 months ago', '4 weeks from now', 'Jan 23, 2004'
|
277
280
|
# And many more formats that are documented in Ruby DateTime API Doc.
|
281
|
+
# In case Time responds to #zone, we know this is Rails environment and we can use Time.zone.parse. The benefit is that the
|
282
|
+
# current timezone is respected and does not have to be specified explicitly. That way even relative dates work as expected.
|
278
283
|
def parse_temporal(value)
|
279
284
|
return Date.current if value =~ /\btoday\b/i
|
280
285
|
return 1.day.ago.to_date if value =~ /\byesterday\b/i
|
@@ -283,7 +288,12 @@ module ScopedSearch
|
|
283
288
|
return (eval($1.strip.gsub(/\s+/,'.').downcase)).to_date if value =~ /\A\s*(\d+\s+\b(?:days?|weeks?|months?|years?)\b\s+\bago)\b\s*\z/i
|
284
289
|
return (eval($1.strip.gsub(/from\s+now/i,'from_now').gsub(/\s+/,'.').downcase)).to_datetime if value =~ /\A\s*(\d+\s+\b(?:hours?|minutes?)\b\s+\bfrom\s+now)\b\s*\z/i
|
285
290
|
return (eval($1.strip.gsub(/from\s+now/i,'from_now').gsub(/\s+/,'.').downcase)).to_date if value =~ /\A\s*(\d+\s+\b(?:days?|weeks?|months?|years?)\b\s+\bfrom\s+now)\b\s*\z/i
|
286
|
-
|
291
|
+
if Time.respond_to?(:zone) && !Time.zone.nil?
|
292
|
+
parsed = Time.zone.parse(value) rescue nil
|
293
|
+
parsed && parsed.to_datetime
|
294
|
+
else
|
295
|
+
DateTime.parse(value, true) rescue nil
|
296
|
+
end
|
287
297
|
end
|
288
298
|
|
289
299
|
# Returns a list of fields that should be searched on by default.
|
@@ -17,6 +17,13 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
17
17
|
t.string :other_c
|
18
18
|
end
|
19
19
|
|
20
|
+
ActiveRecord::Migration.create_table(:quxes, :force => true) do |t|
|
21
|
+
t.string :related
|
22
|
+
t.string :other_a
|
23
|
+
t.string :other_b
|
24
|
+
t.string :other_c
|
25
|
+
end
|
26
|
+
|
20
27
|
ActiveRecord::Migration.create_table(:foos, :force => true) do |t|
|
21
28
|
t.string :string
|
22
29
|
t.string :another
|
@@ -25,6 +32,7 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
25
32
|
t.integer :int
|
26
33
|
t.date :date
|
27
34
|
t.integer :unindexed
|
35
|
+
t.integer :qux_id
|
28
36
|
|
29
37
|
if on_postgresql?
|
30
38
|
t.uuid :uuid
|
@@ -37,8 +45,13 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
37
45
|
belongs_to :foo
|
38
46
|
end
|
39
47
|
|
48
|
+
class ::Qux < ActiveRecord::Base
|
49
|
+
has_many :foos
|
50
|
+
end
|
51
|
+
|
40
52
|
class ::Foo < ActiveRecord::Base
|
41
53
|
has_many :bars
|
54
|
+
belongs_to :qux
|
42
55
|
default_scope { order(:string) }
|
43
56
|
|
44
57
|
scoped_search :on => [:string, :date, :uuid]
|
@@ -55,7 +68,10 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
55
68
|
class ::Infoo < ::Foo
|
56
69
|
end
|
57
70
|
|
58
|
-
@
|
71
|
+
@qux_1 = Qux.create!()
|
72
|
+
@qux_2 = Qux.create!()
|
73
|
+
@foo_1 = Foo.create!(:string => 'foo', :another => 'temp 1', :explicit => 'baz', :int => 9 , :date => 'February 8, 2011' , :unindexed => 10, :qux => @qux_1)
|
74
|
+
@foo_2 = Foo.create!(:string => 'foo', :another => 'temp 2', :explicit => 'baz', :int => 10 , :date => 'February 8, 2011' , :unindexed => 10, :qux => @qux_2)
|
59
75
|
Foo.create!(:string => 'bar', :another => 'temp "2"', :explicit => 'baz', :int => 22 , :date => 'February 10, 2011', :unindexed => 10)
|
60
76
|
Foo.create!(:string => 'baz', :another => nil, :explicit => nil , :int => nil, :date => nil , :unindexed => nil)
|
61
77
|
20.times { Foo.create!(:explicit => "aaa") }
|
@@ -242,5 +258,14 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
242
258
|
Foo.complete_for('int > 2').first.should match(/22/)
|
243
259
|
end
|
244
260
|
end
|
261
|
+
|
262
|
+
context 'autocompleting with value_filter' do
|
263
|
+
it 'should return filtered values' do
|
264
|
+
Foo.complete_for('int =', value_filter: { qux_id: @qux_1.id }).should == ['int = 9']
|
265
|
+
end
|
266
|
+
it 'should return filtered for invalid value' do
|
267
|
+
Foo.complete_for('int =', value_filter: { qux_id: 99 }).should == []
|
268
|
+
end
|
269
|
+
end
|
245
270
|
end
|
246
271
|
end
|
@@ -33,6 +33,7 @@ require "spec_helper"
|
|
33
33
|
has_many :keys, :through => :facts
|
34
34
|
|
35
35
|
scoped_search :relation => :facts, :on => :value, :rename => :facts, :in_key => :keys, :on_key => :name, :complete_value => true
|
36
|
+
scoped_search :relation => :facts, :on => :value, :rename => 'myfacts.value', :aliases => ['prefixed', 'prefixed.value']
|
36
37
|
end
|
37
38
|
class ::MyItem < ::Item
|
38
39
|
end
|
@@ -102,6 +103,20 @@ require "spec_helper"
|
|
102
103
|
it "should find all bars with a fact name color and fact value gold of descendant class" do
|
103
104
|
MyItem.search_for('facts.color = gold').first.name.should eql('barbary')
|
104
105
|
end
|
106
|
+
|
107
|
+
describe 'with prefixed aliases' do
|
108
|
+
it 'should search by the prefix' do
|
109
|
+
Item.search_for('prefixed = green').length.should == 1
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should search by the full length variant' do
|
113
|
+
Item.search_for('prefixed.value = green').length.should == 1
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should not search by just any key with common prefix' do
|
117
|
+
proc { Item.search_for('prefixed.something_which_is_not_defined = green') }.should raise_error(ScopedSearch::QueryNotSupported)
|
118
|
+
end
|
119
|
+
end
|
105
120
|
end
|
106
121
|
end
|
107
122
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scoped_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.1.
|
4
|
+
version: 4.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amos Benari
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2019-05-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -85,6 +85,8 @@ files:
|
|
85
85
|
- Gemfile.activerecord42
|
86
86
|
- Gemfile.activerecord50
|
87
87
|
- Gemfile.activerecord51
|
88
|
+
- Gemfile.activerecord52
|
89
|
+
- Gemfile.activerecord52_with_activesupport52
|
88
90
|
- LICENSE
|
89
91
|
- README.rdoc
|
90
92
|
- Rakefile
|