order_query 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +11 -0
- data/MIT-LICENSE +3 -1
- data/README.md +6 -1
- data/Rakefile +17 -16
- data/lib/order_query/point.rb +9 -6
- data/lib/order_query/sql/where.rb +4 -3
- data/lib/order_query/version.rb +1 -1
- data/spec/gemfiles/{rails_4.gemfile → rails_4_2.gemfile} +2 -2
- data/spec/gemfiles/{rails_5.gemfile → rails_5_0.gemfile} +2 -2
- data/spec/gemfiles/rails_5_1.gemfile +8 -0
- data/spec/order_query_spec.rb +38 -2
- data/spec/spec_helper.rb +3 -4
- metadata +23 -11
- data/spec/gemfiles/rails_4.gemfile.lock +0 -73
- data/spec/gemfiles/rails_5.gemfile.lock +0 -76
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5665c0c52a581228b9afdc57825cd1cfbec7dcae
|
4
|
+
data.tar.gz: a125032c1dfef35a5dfb251c0b4fb4d4f326c1d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a5e1c93db80ef5b81da56f2e551f283ac86c3502df3caf73b0f75f717c4a5cb42e7e31dcc9223eb2b05f565db05f57b613b85c5b6da04629708e1eba657d7b3
|
7
|
+
data.tar.gz: 94809f7775c4634d6f933095cc4671957d0c9fc17b7b7036adbf4c1d6c89b7c4ae9a45dace66c88cc0c42ae0610ff9f335ab7bf7721c4908c34da8aa5a7f8c5c
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## 0.3.4
|
2
|
+
|
3
|
+
* The `before` and `after` methods now accept a boolean argument that indicates
|
4
|
+
whether the relation should exclude the given point or not.
|
5
|
+
By default the given point is excluded, if you want to include it,
|
6
|
+
use `before(false)` / `after(false)`.
|
7
|
+
|
8
|
+
## 0.3.3
|
9
|
+
|
10
|
+
* Now compatible with Rails 5 beta 1.
|
11
|
+
|
1
12
|
## 0.3.2
|
2
13
|
|
3
14
|
* Optimization: do not wrap top-level disjunctive in `AND` when the column has an enumerated order. [Read more](https://github.com/glebm/order_query/issues/3#issuecomment-54764638).
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -11,7 +11,7 @@ This gem finds the next or previous record(s) relative to the current one effici
|
|
11
11
|
Add to Gemfile:
|
12
12
|
|
13
13
|
```ruby
|
14
|
-
gem 'order_query', '~> 0.3.
|
14
|
+
gem 'order_query', '~> 0.3.4'
|
15
15
|
```
|
16
16
|
|
17
17
|
## Usage
|
@@ -66,6 +66,11 @@ p.next #=> #<Post>
|
|
66
66
|
p.position #=> 5
|
67
67
|
```
|
68
68
|
|
69
|
+
The `before` and `after` methods also accept a boolean argument that indicates
|
70
|
+
whether the relation should exclude the given point or not.
|
71
|
+
By default the given point is excluded, if you want to include it,
|
72
|
+
use `before(false)` / `after(false)`.
|
73
|
+
|
69
74
|
Looping to the first / last record is enabled for `next` / `previous` by default. Pass `false` to disable:
|
70
75
|
|
71
76
|
```ruby
|
data/Rakefile
CHANGED
@@ -13,27 +13,28 @@ desc 'Test all Gemfiles from spec/*.gemfile'
|
|
13
13
|
task :test_all_gemfiles do
|
14
14
|
require 'pty'
|
15
15
|
require 'shellwords'
|
16
|
-
cmd = 'bundle --quiet && bundle exec rake --trace'
|
16
|
+
cmd = 'bundle install --quiet && bundle exec rake --trace'
|
17
17
|
statuses = Dir.glob('./spec/gemfiles/*{[!.lock]}').map do |gemfile|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
Bundler.with_clean_env do
|
19
|
+
env = {'BUNDLE_GEMFILE' => gemfile}
|
20
|
+
$stderr.puts "Testing #{File.basename(gemfile)}:\n export #{env.map { |k, v| "#{k}=#{Shellwords.escape v}" } * ' '}; #{cmd}"
|
21
|
+
PTY.spawn(env, cmd) do |r, _w, pid|
|
22
|
+
begin
|
23
|
+
r.each_line { |l| puts l }
|
24
|
+
rescue Errno::EIO
|
25
|
+
# Errno:EIO error means that the process has finished giving output.
|
26
|
+
ensure
|
27
|
+
::Process.wait pid
|
28
|
+
end
|
28
29
|
end
|
30
|
+
[$? && $?.exitstatus == 0, gemfile]
|
29
31
|
end
|
30
|
-
[$? && $?.exitstatus == 0, cmd_with_env]
|
31
32
|
end
|
32
|
-
|
33
|
-
if
|
34
|
-
$stderr.puts
|
33
|
+
failed_gemfiles = statuses.reject(&:first).map { |(_status, gemfile)| gemfile }
|
34
|
+
if failed_gemfiles.empty?
|
35
|
+
$stderr.puts "✓ Tests pass with all #{statuses.size} gemfiles"
|
35
36
|
else
|
36
|
-
$stderr.puts "❌ FAILING (#{
|
37
|
+
$stderr.puts "❌ FAILING (#{failed_gemfiles.size} / #{statuses.size})\n#{failed_gemfiles * "\n"}"
|
37
38
|
exit 1
|
38
39
|
end
|
39
40
|
end
|
data/lib/order_query/point.rb
CHANGED
@@ -31,20 +31,23 @@ module OrderQuery
|
|
31
31
|
space.count - after.count
|
32
32
|
end
|
33
33
|
|
34
|
+
# @param [true, false] strict choose if the given scope should include or not the record, default not to include it (strict true)
|
34
35
|
# @return [ActiveRecord::Relation]
|
35
|
-
def after
|
36
|
-
side :after
|
36
|
+
def after(strict = true)
|
37
|
+
side :after, strict
|
37
38
|
end
|
38
39
|
|
40
|
+
# @param [true, false] strict choose if the given scope should include or not the record, default not to include it (strict true)
|
39
41
|
# @return [ActiveRecord::Relation]
|
40
|
-
def before
|
41
|
-
side :before
|
42
|
+
def before(strict = true)
|
43
|
+
side :before, strict
|
42
44
|
end
|
43
45
|
|
44
46
|
# @param [:before, :after] side
|
47
|
+
# @param [true, false] strict choose if the given scope should include or not the record, default not to include it (strict true)
|
45
48
|
# @return [ActiveRecord::Relation]
|
46
|
-
def side(side)
|
47
|
-
query, query_args = @where_sql.build(side)
|
49
|
+
def side(side, strict = true)
|
50
|
+
query, query_args = @where_sql.build(side, strict)
|
48
51
|
scope = if side == :after
|
49
52
|
space.scope
|
50
53
|
else
|
@@ -19,10 +19,11 @@ module OrderQuery
|
|
19
19
|
# invoice < 3 OR
|
20
20
|
# invoices = 3 AND (
|
21
21
|
# ... ))
|
22
|
-
def build(side)
|
22
|
+
def build(side, strict = true)
|
23
23
|
# generate pairs of terms such as sales < 5, sales = 5
|
24
|
-
terms = @columns.map { |col|
|
25
|
-
|
24
|
+
terms = @columns.map.with_index { |col, i|
|
25
|
+
be_strict = (i != @columns.size - 1) ? true : strict
|
26
|
+
[where_side(col, side, be_strict), where_tie(col)].reject { |x| x == WHERE_IDENTITY }
|
26
27
|
}
|
27
28
|
# group pairwise with OR, and nest with AND
|
28
29
|
query = foldr_terms terms.map { |pair| join_terms 'OR'.freeze, *pair }, 'AND'.freeze
|
data/lib/order_query/version.rb
CHANGED
data/spec/order_query_spec.rb
CHANGED
@@ -61,7 +61,7 @@ describe 'OrderQuery' do
|
|
61
61
|
wrap_top_level_or wrap_top_level_or
|
62
62
|
|
63
63
|
context 'Issue test model' do
|
64
|
-
t
|
64
|
+
t = Time.now
|
65
65
|
datasets = [
|
66
66
|
[
|
67
67
|
['high', 5, 0, t, true],
|
@@ -226,7 +226,7 @@ describe 'OrderQuery' do
|
|
226
226
|
}
|
227
227
|
|
228
228
|
it 'Point' do
|
229
|
-
post
|
229
|
+
post = create_post
|
230
230
|
point = OrderQuery::Point.new(post, space)
|
231
231
|
expect(point.inspect).to(
|
232
232
|
eq %Q(#<OrderQuery::Point @record=#<Post id: #{post.id}, pinned: false, published_at: #{post.attribute_for_inspect(:published_at)}> @space=#<OrderQuery::Space @columns=[(pinned [true, false] desc), (id unique asc)] @base_scope=Post(id: integer, pinned: boolean, published_at: datetime)>>)
|
@@ -275,6 +275,42 @@ describe 'OrderQuery' do
|
|
275
275
|
end
|
276
276
|
end
|
277
277
|
|
278
|
+
context 'after/before no strict' do
|
279
|
+
context 'by middle attribute in search order' do
|
280
|
+
let!(:base) { Post.create! pinned: true, published_at: Time.now }
|
281
|
+
let!(:older) { Post.create! pinned: true, published_at: Time.now + 1.hour }
|
282
|
+
let!(:younger) { Post.create! pinned: true, published_at: Time.now - 1.hour }
|
283
|
+
|
284
|
+
it 'includes first element' do
|
285
|
+
point = Post.order_list_at(base)
|
286
|
+
|
287
|
+
expect(point.after.count).to eq 1
|
288
|
+
expect(point.after.to_a).to eq [younger]
|
289
|
+
|
290
|
+
expect(point.after(false).count).to eq 2
|
291
|
+
expect(point.after(false).to_a).to eq [base, younger]
|
292
|
+
expect(point.before(false).to_a).to eq [base, older]
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
context 'by last attribute in search order' do
|
297
|
+
let!(:base) { Post.create! pinned: true, published_at: Time.new(2016, 5, 1, 5, 4, 3), id: 6 }
|
298
|
+
let!(:previous) { Post.create! pinned: true, published_at: Time.new(2016, 5, 1, 5, 4, 3), id: 4 }
|
299
|
+
let!(:next_one) { Post.create! pinned: true, published_at: Time.new(2016, 5, 1, 5, 4, 3), id: 9 }
|
300
|
+
|
301
|
+
it 'includes first element' do
|
302
|
+
point = Post.order_list_at(base)
|
303
|
+
|
304
|
+
expect(point.after.count).to eq 1
|
305
|
+
expect(point.after.to_a).to eq [previous]
|
306
|
+
|
307
|
+
expect(point.after(false).count).to eq 2
|
308
|
+
expect(point.after(false).to_a).to eq [base, previous]
|
309
|
+
expect(point.before(false).to_a).to eq [base, next_one]
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
278
314
|
before do
|
279
315
|
Post.delete_all
|
280
316
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
1
|
# Configure Rails Environment
|
3
2
|
ENV['RAILS_ENV'] = ENV['RACK_ENV'] = 'test'
|
4
|
-
if ENV['
|
5
|
-
require '
|
6
|
-
|
3
|
+
if ENV['COVERAGE'] && !%w[rbx jruby].include?(RUBY_ENGINE)
|
4
|
+
require 'simplecov'
|
5
|
+
SimpleCov.command_name 'RSpec'
|
7
6
|
end
|
8
7
|
require 'order_query'
|
9
8
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: order_query
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gleb Mazovetskiy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -78,6 +78,20 @@ dependencies:
|
|
78
78
|
- - "~>"
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: '10.2'
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: simplecov
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
81
95
|
description: Find next / previous Active Record(s) in one efficient query
|
82
96
|
email: glex.spb@gmail.com
|
83
97
|
executables: []
|
@@ -98,10 +112,9 @@ files:
|
|
98
112
|
- lib/order_query/sql/order_by.rb
|
99
113
|
- lib/order_query/sql/where.rb
|
100
114
|
- lib/order_query/version.rb
|
101
|
-
- spec/gemfiles/
|
102
|
-
- spec/gemfiles/
|
103
|
-
- spec/gemfiles/
|
104
|
-
- spec/gemfiles/rails_5.gemfile.lock
|
115
|
+
- spec/gemfiles/rails_4_2.gemfile
|
116
|
+
- spec/gemfiles/rails_5_0.gemfile
|
117
|
+
- spec/gemfiles/rails_5_1.gemfile
|
105
118
|
- spec/order_query_spec.rb
|
106
119
|
- spec/spec_helper.rb
|
107
120
|
homepage: https://github.com/glebm/order_query
|
@@ -125,14 +138,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
138
|
version: '0'
|
126
139
|
requirements: []
|
127
140
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.
|
141
|
+
rubygems_version: 2.6.12
|
129
142
|
signing_key:
|
130
143
|
specification_version: 4
|
131
144
|
summary: Find next / previous Active Record(s) in one query
|
132
145
|
test_files:
|
133
|
-
- spec/gemfiles/rails_4.gemfile
|
134
|
-
- spec/gemfiles/rails_4.gemfile.lock
|
135
|
-
- spec/gemfiles/rails_5.gemfile
|
136
|
-
- spec/gemfiles/rails_5.gemfile.lock
|
137
146
|
- spec/order_query_spec.rb
|
138
147
|
- spec/spec_helper.rb
|
148
|
+
- spec/gemfiles/rails_5_1.gemfile
|
149
|
+
- spec/gemfiles/rails_4_2.gemfile
|
150
|
+
- spec/gemfiles/rails_5_0.gemfile
|
@@ -1,73 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: ../../
|
3
|
-
specs:
|
4
|
-
order_query (0.3.2)
|
5
|
-
activerecord (>= 4.0, < 6.0)
|
6
|
-
activesupport (>= 4.0, < 6.0)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
activemodel (4.2.5)
|
12
|
-
activesupport (= 4.2.5)
|
13
|
-
builder (~> 3.1)
|
14
|
-
activerecord (4.2.5)
|
15
|
-
activemodel (= 4.2.5)
|
16
|
-
activesupport (= 4.2.5)
|
17
|
-
arel (~> 6.0)
|
18
|
-
activesupport (4.2.5)
|
19
|
-
i18n (~> 0.7)
|
20
|
-
json (~> 1.7, >= 1.7.7)
|
21
|
-
minitest (~> 5.1)
|
22
|
-
thread_safe (~> 0.3, >= 0.3.4)
|
23
|
-
tzinfo (~> 1.1)
|
24
|
-
arel (6.0.3)
|
25
|
-
builder (3.2.2)
|
26
|
-
byebug (8.2.1)
|
27
|
-
codeclimate-test-reporter (0.4.8)
|
28
|
-
simplecov (>= 0.7.1, < 1.0.0)
|
29
|
-
diff-lcs (1.2.5)
|
30
|
-
docile (1.1.5)
|
31
|
-
i18n (0.7.0)
|
32
|
-
json (1.8.3)
|
33
|
-
minitest (5.8.3)
|
34
|
-
rake (10.4.2)
|
35
|
-
rspec (3.4.0)
|
36
|
-
rspec-core (~> 3.4.0)
|
37
|
-
rspec-expectations (~> 3.4.0)
|
38
|
-
rspec-mocks (~> 3.4.0)
|
39
|
-
rspec-core (3.4.1)
|
40
|
-
rspec-support (~> 3.4.0)
|
41
|
-
rspec-expectations (3.4.0)
|
42
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
-
rspec-support (~> 3.4.0)
|
44
|
-
rspec-mocks (3.4.0)
|
45
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
-
rspec-support (~> 3.4.0)
|
47
|
-
rspec-support (3.4.1)
|
48
|
-
simplecov (0.11.1)
|
49
|
-
docile (~> 1.1.0)
|
50
|
-
json (~> 1.8)
|
51
|
-
simplecov-html (~> 0.10.0)
|
52
|
-
simplecov-html (0.10.0)
|
53
|
-
sqlite3 (1.3.11)
|
54
|
-
thread_safe (0.3.5)
|
55
|
-
tzinfo (1.2.2)
|
56
|
-
thread_safe (~> 0.1)
|
57
|
-
|
58
|
-
PLATFORMS
|
59
|
-
ruby
|
60
|
-
|
61
|
-
DEPENDENCIES
|
62
|
-
activerecord (~> 4.0)
|
63
|
-
activerecord-jdbcsqlite3-adapter
|
64
|
-
activesupport (~> 4.0)
|
65
|
-
byebug
|
66
|
-
codeclimate-test-reporter
|
67
|
-
order_query!
|
68
|
-
rake (~> 10.2)
|
69
|
-
rspec (~> 3.4)
|
70
|
-
sqlite3 (>= 1.3.11)
|
71
|
-
|
72
|
-
BUNDLED WITH
|
73
|
-
1.11.2
|
@@ -1,76 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: ../../
|
3
|
-
specs:
|
4
|
-
order_query (0.3.2)
|
5
|
-
activerecord (>= 4.0, < 6.0)
|
6
|
-
activesupport (>= 4.0, < 6.0)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
activemodel (5.0.0.beta1)
|
12
|
-
activesupport (= 5.0.0.beta1)
|
13
|
-
builder (~> 3.1)
|
14
|
-
activerecord (5.0.0.beta1)
|
15
|
-
activemodel (= 5.0.0.beta1)
|
16
|
-
activesupport (= 5.0.0.beta1)
|
17
|
-
arel (~> 7.0)
|
18
|
-
activesupport (5.0.0.beta1)
|
19
|
-
concurrent-ruby (~> 1.0)
|
20
|
-
i18n (~> 0.7)
|
21
|
-
json (~> 1.7, >= 1.7.7)
|
22
|
-
method_source
|
23
|
-
minitest (~> 5.1)
|
24
|
-
tzinfo (~> 1.1)
|
25
|
-
arel (7.0.0)
|
26
|
-
builder (3.2.2)
|
27
|
-
byebug (8.2.1)
|
28
|
-
codeclimate-test-reporter (0.4.8)
|
29
|
-
simplecov (>= 0.7.1, < 1.0.0)
|
30
|
-
concurrent-ruby (1.0.0)
|
31
|
-
diff-lcs (1.2.5)
|
32
|
-
docile (1.1.5)
|
33
|
-
i18n (0.7.0)
|
34
|
-
json (1.8.3)
|
35
|
-
method_source (0.8.2)
|
36
|
-
minitest (5.8.3)
|
37
|
-
rake (10.4.2)
|
38
|
-
rspec (3.4.0)
|
39
|
-
rspec-core (~> 3.4.0)
|
40
|
-
rspec-expectations (~> 3.4.0)
|
41
|
-
rspec-mocks (~> 3.4.0)
|
42
|
-
rspec-core (3.4.1)
|
43
|
-
rspec-support (~> 3.4.0)
|
44
|
-
rspec-expectations (3.4.0)
|
45
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
-
rspec-support (~> 3.4.0)
|
47
|
-
rspec-mocks (3.4.0)
|
48
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
-
rspec-support (~> 3.4.0)
|
50
|
-
rspec-support (3.4.1)
|
51
|
-
simplecov (0.11.1)
|
52
|
-
docile (~> 1.1.0)
|
53
|
-
json (~> 1.8)
|
54
|
-
simplecov-html (~> 0.10.0)
|
55
|
-
simplecov-html (0.10.0)
|
56
|
-
sqlite3 (1.3.11)
|
57
|
-
thread_safe (0.3.5)
|
58
|
-
tzinfo (1.2.2)
|
59
|
-
thread_safe (~> 0.1)
|
60
|
-
|
61
|
-
PLATFORMS
|
62
|
-
ruby
|
63
|
-
|
64
|
-
DEPENDENCIES
|
65
|
-
activerecord (= 5.0.0.beta1)
|
66
|
-
activerecord-jdbcsqlite3-adapter
|
67
|
-
activesupport (= 5.0.0.beta1)
|
68
|
-
byebug
|
69
|
-
codeclimate-test-reporter
|
70
|
-
order_query!
|
71
|
-
rake (~> 10.2)
|
72
|
-
rspec (~> 3.4)
|
73
|
-
sqlite3 (>= 1.3.11)
|
74
|
-
|
75
|
-
BUNDLED WITH
|
76
|
-
1.11.2
|