find_with_order 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +98 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +32 -24
- data/README.md +13 -8
- data/find_with_order.gemspec +2 -2
- data/gemfiles/3.2.gemfile +3 -3
- data/gemfiles/4.2.gemfile +3 -3
- data/gemfiles/5.0.gemfile +3 -3
- data/gemfiles/5.1.gemfile +3 -4
- data/gemfiles/5.2.gemfile +3 -3
- data/gemfiles/6.0.gemfile +14 -0
- data/gemfiles/6.1.gemfile +14 -0
- data/lib/find_with_order/mysql_support.rb +3 -3
- data/lib/find_with_order/version.rb +1 -1
- metadata +7 -6
- data/.travis.yml +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 015a48fca352ef1bb4b6aab8a206ad690dfea36462f5b33f7807bee6e786144a
|
4
|
+
data.tar.gz: beb3426fda4db3e29cb0ab0908ffcda2911f6564a6673699d468f6ea3e86a702
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 100044ac0115988577753964bea0b55b333943a688163caf36230a93ae06fccd27874d94cc0bd5b8644d946d33e0ac73c0f6427223a379824c548ca709d8b656
|
7
|
+
data.tar.gz: 0bc3c0bfa032cce6fad60a22e06f9ae3e3842f46054481eb3657a2b61ffb836af93771c15f7429f23548dd75cb0ad120361a0cdf2b97706c1889be007046e4ea
|
@@ -0,0 +1,98 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
paths-ignore:
|
6
|
+
- 'README.md'
|
7
|
+
- 'CHANGELOG.md'
|
8
|
+
pull_request:
|
9
|
+
branches: [ master ]
|
10
|
+
paths-ignore:
|
11
|
+
- 'README.md'
|
12
|
+
- 'CHANGELOG.md'
|
13
|
+
|
14
|
+
jobs:
|
15
|
+
test:
|
16
|
+
runs-on: ubuntu-latest
|
17
|
+
name: Test
|
18
|
+
if: "contains(github.event.commits[0].message, '[ci skip]') == false"
|
19
|
+
strategy:
|
20
|
+
fail-fast: false
|
21
|
+
matrix:
|
22
|
+
db:
|
23
|
+
- mysql
|
24
|
+
- pg
|
25
|
+
ruby:
|
26
|
+
# - 2.2 # skip Ruby 2.2 since mysql2 raises segmentation fault at 0x0000000000000000
|
27
|
+
# See: https://github.community/t/mysql2-segmentation-fault-at-0x0000000000000000/159283
|
28
|
+
- 2.6
|
29
|
+
- 2.7
|
30
|
+
gemfile:
|
31
|
+
- 3.2.gemfile
|
32
|
+
- 4.2.gemfile
|
33
|
+
- 5.0.gemfile
|
34
|
+
- 5.1.gemfile
|
35
|
+
- 5.2.gemfile
|
36
|
+
- 6.0.gemfile
|
37
|
+
- 6.1.gemfile
|
38
|
+
exclude:
|
39
|
+
- gemfile: 3.2.gemfile
|
40
|
+
ruby: 2.6
|
41
|
+
- gemfile: 3.2.gemfile
|
42
|
+
ruby: 2.7
|
43
|
+
- gemfile: 4.2.gemfile
|
44
|
+
ruby: 2.7
|
45
|
+
- gemfile: 6.0.gemfile
|
46
|
+
ruby: 2.2
|
47
|
+
- gemfile: 6.1.gemfile
|
48
|
+
ruby: 2.2
|
49
|
+
env:
|
50
|
+
BUNDLE_GEMFILE: "gemfiles/${{ matrix.gemfile }}"
|
51
|
+
DB: "${{ matrix.db }}"
|
52
|
+
|
53
|
+
services:
|
54
|
+
mysql:
|
55
|
+
image: mysql:5.6
|
56
|
+
env:
|
57
|
+
MYSQL_ROOT_PASSWORD: root_password
|
58
|
+
MYSQL_USER: developer
|
59
|
+
MYSQL_PASSWORD: developer_password
|
60
|
+
MYSQL_DATABASE: github_actions_test
|
61
|
+
ports:
|
62
|
+
- 3306:3306
|
63
|
+
# Set health checks to wait until mysql has started
|
64
|
+
options: >-
|
65
|
+
--health-cmd "mysqladmin ping"
|
66
|
+
--health-interval 10s
|
67
|
+
--health-timeout 5s
|
68
|
+
--health-retries 3
|
69
|
+
postgres:
|
70
|
+
image: postgres:9.6
|
71
|
+
env:
|
72
|
+
POSTGRES_USER: developer
|
73
|
+
POSTGRES_PASSWORD: developer_password
|
74
|
+
POSTGRES_DB: github_actions_test
|
75
|
+
ports:
|
76
|
+
- 5432:5432
|
77
|
+
# Set health checks to wait until postgres has started
|
78
|
+
options: >-
|
79
|
+
--health-cmd pg_isready
|
80
|
+
--health-interval 10s
|
81
|
+
--health-timeout 5s
|
82
|
+
--health-retries 3
|
83
|
+
|
84
|
+
steps:
|
85
|
+
- name: Checkout
|
86
|
+
uses: actions/checkout@v2
|
87
|
+
- name: Setup Ruby
|
88
|
+
uses: ruby/setup-ruby@v1
|
89
|
+
with:
|
90
|
+
ruby-version: ${{ matrix.ruby }}
|
91
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
92
|
+
- name: Run tests
|
93
|
+
run: bundle exec rake
|
94
|
+
- name: Publish code coverage
|
95
|
+
if: ${{ success() && env.CC_TEST_REPORTER_ID }}
|
96
|
+
uses: paambaati/codeclimate-action@v2.7.5
|
97
|
+
env:
|
98
|
+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,24 +1,32 @@
|
|
1
|
-
## Change Log
|
2
|
-
|
3
|
-
### v1.2.1
|
4
|
-
- [#
|
5
|
-
|
6
|
-
|
7
|
-
- [#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
1
|
+
## Change Log
|
2
|
+
|
3
|
+
### [v1.3.0](https://github.com/khiav223577/find_with_order/compare/v1.2.1...v1.3.0) 2019/05/12
|
4
|
+
- [#18](https://github.com/khiav223577/find_with_order/pull/18) Support psql uuid type (@khiav223577)
|
5
|
+
- [#17](https://github.com/khiav223577/find_with_order/pull/17) Remove deprecated codeclimate-test-reporter gem and update travis config (@khiav223577)
|
6
|
+
- [#16](https://github.com/khiav223577/find_with_order/pull/16) Fix: broken test cases after bundler 2.0 was released (@khiav223577)
|
7
|
+
- [#14](https://github.com/khiav223577/find_with_order/pull/14) test rails 5.2 (@khiav223577)
|
8
|
+
- [#13](https://github.com/khiav223577/find_with_order/pull/13) should test both 5.0.x and 5.1.x (@khiav223577)
|
9
|
+
- [#12](https://github.com/khiav223577/find_with_order/pull/12) test find_with_order in rails 5.1.x (@khiav223577)
|
10
|
+
|
11
|
+
### [v1.2.1](https://github.com/khiav223577/find_with_order/compare/v1.2.0...v1.2.1) 2017/09/21
|
12
|
+
- [#11](https://github.com/khiav223577/find_with_order/pull/11) ambiguous id when not specify table name (@khiav223577)
|
13
|
+
|
14
|
+
### [v1.2.0](https://github.com/khiav223577/find_with_order/compare/v1.1.1...v1.2.0) 2017/07/01
|
15
|
+
- [#10](https://github.com/khiav223577/find_with_order/pull/10) Supports #with_order method (@khiav223577)
|
16
|
+
|
17
|
+
### [v1.1.1](https://github.com/khiav223577/find_with_order/compare/v1.1.0...v1.1.1) 2017/06/22
|
18
|
+
- [#9](https://github.com/khiav223577/find_with_order/pull/9) Restrict dependency to activerecord (@khiav223577)
|
19
|
+
- [#8](https://github.com/khiav223577/find_with_order/pull/8) try to fix travis (@khiav223577)
|
20
|
+
|
21
|
+
### [v1.1.0](https://github.com/khiav223577/find_with_order/compare/v1.0.1...v1.1.0) 2017/03/22
|
22
|
+
- [#7](https://github.com/khiav223577/find_with_order/pull/7) Add PostgreSQL support (@khiav223577)
|
23
|
+
|
24
|
+
### [v1.0.1](https://github.com/khiav223577/find_with_order/compare/v1.0.0...v1.0.1) 2017/03/03
|
25
|
+
- [#6](https://github.com/khiav223577/find_with_order/pull/6) Fix ambiguous id (@khiav223577)
|
26
|
+
|
27
|
+
### [v1.0.0](https://github.com/khiav223577/find_with_order/compare/v0.0.2...v1.0.0) 2017/02/23
|
28
|
+
- [#3](https://github.com/khiav223577/find_with_order/pull/3) where with order (@khiav223577)
|
29
|
+
|
30
|
+
### [v0.0.2](https://github.com/khiav223577/find_with_order/compare/v0.0.1...v0.0.2) 2017/02/22
|
31
|
+
- [#2](https://github.com/khiav223577/find_with_order/pull/2) Fix Rails 3 doesn't have #none method (@khiav223577)
|
32
|
+
- [#1](https://github.com/khiav223577/find_with_order/pull/1) add find_with_order (@khiav223577)
|
data/README.md
CHANGED
@@ -2,13 +2,18 @@
|
|
2
2
|
# FindWithOrder
|
3
3
|
|
4
4
|
[![Gem Version](https://img.shields.io/gem/v/find_with_order.svg?style=flat)](https://rubygems.org/gems/find_with_order)
|
5
|
-
[![Build Status](https://
|
5
|
+
[![Build Status](https://github.com/khiav223577/find_with_order/workflows/Ruby/badge.svg)](https://github.com/khiav223577/find_with_order/actions)
|
6
6
|
[![RubyGems](http://img.shields.io/gem/dt/find_with_order.svg?style=flat)](https://rubygems.org/gems/find_with_order)
|
7
7
|
[![Code Climate](https://codeclimate.com/github/khiav223577/find_with_order/badges/gpa.svg)](https://codeclimate.com/github/khiav223577/find_with_order)
|
8
8
|
[![Test Coverage](https://codeclimate.com/github/khiav223577/find_with_order/badges/coverage.svg)](https://codeclimate.com/github/khiav223577/find_with_order/coverage)
|
9
9
|
|
10
10
|
Find records in the same order of input array.
|
11
11
|
|
12
|
+
## Supports
|
13
|
+
- Ruby 2.2 ~ 2.7
|
14
|
+
- Rails 3.2, 4.2, 5.0, 5.1, 5.2, 6.0
|
15
|
+
- MySQL, PostgreSQL
|
16
|
+
|
12
17
|
## Installation
|
13
18
|
|
14
19
|
Add this line to your application's Gemfile:
|
@@ -32,21 +37,21 @@ Or install it yourself as:
|
|
32
37
|
ids = [3, 1, 5]
|
33
38
|
|
34
39
|
User.find(ids).map(&:id)
|
35
|
-
# => [1, 3, 5]
|
40
|
+
# => [1, 3, 5]
|
36
41
|
|
37
42
|
User.find_with_order(ids).map(&:id)
|
38
|
-
# => [3, 1, 5]
|
43
|
+
# => [3, 1, 5]
|
39
44
|
```
|
40
45
|
|
41
46
|
### Support ordering by other columns: `where_with_order`
|
42
47
|
```rb
|
43
|
-
names = %w(Pearl John
|
48
|
+
names = %w(Pearl John Doggy)
|
44
49
|
|
45
50
|
User.where(name: names).pluck(:name)
|
46
|
-
# => ['John', 'Pearl', '
|
51
|
+
# => ['John', 'Pearl', 'Doggy']
|
47
52
|
|
48
53
|
User.where_with_order(:name, names).pluck(:name)
|
49
|
-
# => ['Pearl', 'John', '
|
54
|
+
# => ['Pearl', 'John', 'Doggy']
|
50
55
|
```
|
51
56
|
|
52
57
|
### Support ordering only part of results: `with_order`
|
@@ -54,10 +59,10 @@ User.where_with_order(:name, names).pluck(:name)
|
|
54
59
|
names = %w(Pearl John)
|
55
60
|
|
56
61
|
User.leader.with_order(:name, names).pluck(:name)
|
57
|
-
# => ['Pearl', 'John', '
|
62
|
+
# => ['Pearl', 'John', 'Doggy']
|
58
63
|
|
59
64
|
User.leader.with_order(:name, names, null_first: true).pluck(:name)
|
60
|
-
# => ['
|
65
|
+
# => ['Doggy', 'Pearl', 'John']
|
61
66
|
```
|
62
67
|
|
63
68
|
|
data/find_with_order.gemspec
CHANGED
@@ -26,11 +26,11 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.bindir = "exe"
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
|
-
spec.metadata
|
29
|
+
spec.metadata = {
|
30
30
|
'homepage_uri' => 'https://github.com/khiav223577/find_with_order',
|
31
31
|
'changelog_uri' => 'https://github.com/khiav223577/find_with_order/blob/master/CHANGELOG.md',
|
32
32
|
'source_code_uri' => 'https://github.com/khiav223577/find_with_order',
|
33
|
-
'documentation_uri' => '
|
33
|
+
'documentation_uri' => 'https://www.rubydoc.info/gems/find_with_order',
|
34
34
|
'bug_tracker_uri' => 'https://github.com/khiav223577/find_with_order/issues',
|
35
35
|
}
|
36
36
|
|
data/gemfiles/3.2.gemfile
CHANGED
@@ -4,10 +4,10 @@ gem "activerecord", "~> 3.2.0"
|
|
4
4
|
|
5
5
|
group :test do
|
6
6
|
case ENV['DB']
|
7
|
-
when
|
8
|
-
when
|
7
|
+
when 'mysql' ; gem 'mysql2' , '0.4.10'
|
8
|
+
when 'pg' ; gem 'pg', '~> 0.18'
|
9
9
|
end
|
10
|
-
gem "simplecov"
|
10
|
+
gem "simplecov", '< 0.18'
|
11
11
|
end
|
12
12
|
|
13
13
|
gemspec :path => "../"
|
data/gemfiles/4.2.gemfile
CHANGED
@@ -4,10 +4,10 @@ gem "activerecord", "~> 4.2.0"
|
|
4
4
|
|
5
5
|
group :test do
|
6
6
|
case ENV['DB']
|
7
|
-
when
|
8
|
-
when
|
7
|
+
when 'mysql' ; gem 'mysql2' , '0.4.10'
|
8
|
+
when 'pg' ; gem 'pg', '~> 0.18'
|
9
9
|
end
|
10
|
-
gem "simplecov"
|
10
|
+
gem "simplecov", '< 0.18'
|
11
11
|
end
|
12
12
|
|
13
13
|
gemspec :path => "../"
|
data/gemfiles/5.0.gemfile
CHANGED
@@ -4,10 +4,10 @@ gem "activerecord", "~> 5.0.0"
|
|
4
4
|
|
5
5
|
group :test do
|
6
6
|
case ENV['DB']
|
7
|
-
when
|
8
|
-
when
|
7
|
+
when 'mysql' ; gem 'mysql2' , '0.4.10'
|
8
|
+
when 'pg' ; gem 'pg', '~> 0.18'
|
9
9
|
end
|
10
|
-
gem "simplecov"
|
10
|
+
gem "simplecov", '< 0.18'
|
11
11
|
end
|
12
12
|
|
13
13
|
gemspec :path => "../"
|
data/gemfiles/5.1.gemfile
CHANGED
@@ -4,11 +4,10 @@ gem "activerecord", "~> 5.1.0"
|
|
4
4
|
|
5
5
|
group :test do
|
6
6
|
case ENV['DB']
|
7
|
-
when
|
8
|
-
when
|
7
|
+
when 'mysql' ; gem 'mysql2' , '0.4.10'
|
8
|
+
when 'pg' ; gem 'pg', '~> 0.18'
|
9
9
|
end
|
10
|
-
gem "simplecov"
|
10
|
+
gem "simplecov", '< 0.18'
|
11
11
|
end
|
12
12
|
|
13
13
|
gemspec :path => "../"
|
14
|
-
|
data/gemfiles/5.2.gemfile
CHANGED
@@ -4,10 +4,10 @@ gem "activerecord", "~> 5.2.0"
|
|
4
4
|
|
5
5
|
group :test do
|
6
6
|
case ENV['DB']
|
7
|
-
when
|
8
|
-
when
|
7
|
+
when 'mysql' ; gem 'mysql2' , '0.5.1'
|
8
|
+
when 'pg' ; gem 'pg', '~> 0.18'
|
9
9
|
end
|
10
|
-
gem "simplecov"
|
10
|
+
gem "simplecov", '< 0.18'
|
11
11
|
end
|
12
12
|
|
13
13
|
gemspec :path => "../"
|
@@ -4,7 +4,7 @@ module FindWithOrder::MysqlSupport
|
|
4
4
|
class << self
|
5
5
|
def find_with_order(relation, ids)
|
6
6
|
relation.where(id: ids)
|
7
|
-
.order("field(#{relation.table_name}.id, #{ids.join(',')})")
|
7
|
+
.order(Arel.sql("field(#{relation.table_name}.id, #{ids.join(',')})"))
|
8
8
|
.to_a
|
9
9
|
end
|
10
10
|
|
@@ -18,8 +18,8 @@ module FindWithOrder::MysqlSupport
|
|
18
18
|
else
|
19
19
|
column = column.to_s
|
20
20
|
end
|
21
|
-
return relation.order("field(#{column}, #{ids.map(&:inspect).join(',')})") if null_first
|
22
|
-
return relation.order("field(#{column}, #{ids.reverse.map(&:inspect).join(',')}) DESC")
|
21
|
+
return relation.order(Arel.sql("field(#{column}, #{ids.map(&:inspect).join(',')})")) if null_first
|
22
|
+
return relation.order(Arel.sql("field(#{column}, #{ids.reverse.map(&:inspect).join(',')}) DESC"))
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: find_with_order
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- khiav reoy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,8 +108,8 @@ executables: []
|
|
108
108
|
extensions: []
|
109
109
|
extra_rdoc_files: []
|
110
110
|
files:
|
111
|
+
- ".github/workflows/ruby.yml"
|
111
112
|
- ".gitignore"
|
112
|
-
- ".travis.yml"
|
113
113
|
- CHANGELOG.md
|
114
114
|
- CODE_OF_CONDUCT.md
|
115
115
|
- LICENSE.txt
|
@@ -123,6 +123,8 @@ files:
|
|
123
123
|
- gemfiles/5.0.gemfile
|
124
124
|
- gemfiles/5.1.gemfile
|
125
125
|
- gemfiles/5.2.gemfile
|
126
|
+
- gemfiles/6.0.gemfile
|
127
|
+
- gemfiles/6.1.gemfile
|
126
128
|
- lib/find_with_order.rb
|
127
129
|
- lib/find_with_order/mysql_support.rb
|
128
130
|
- lib/find_with_order/pg_support.rb
|
@@ -134,7 +136,7 @@ metadata:
|
|
134
136
|
homepage_uri: https://github.com/khiav223577/find_with_order
|
135
137
|
changelog_uri: https://github.com/khiav223577/find_with_order/blob/master/CHANGELOG.md
|
136
138
|
source_code_uri: https://github.com/khiav223577/find_with_order
|
137
|
-
documentation_uri:
|
139
|
+
documentation_uri: https://www.rubydoc.info/gems/find_with_order
|
138
140
|
bug_tracker_uri: https://github.com/khiav223577/find_with_order/issues
|
139
141
|
post_install_message:
|
140
142
|
rdoc_options: []
|
@@ -151,8 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
153
|
- !ruby/object:Gem::Version
|
152
154
|
version: '0'
|
153
155
|
requirements: []
|
154
|
-
|
155
|
-
rubygems_version: 2.7.6
|
156
|
+
rubygems_version: 3.2.14
|
156
157
|
signing_key:
|
157
158
|
specification_version: 4
|
158
159
|
summary: A simple way to find records in the same order of input array.
|
data/.travis.yml
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
sudo: false
|
2
|
-
env:
|
3
|
-
global:
|
4
|
-
- CC_TEST_REPORTER_ID=6384ecacad280dc863595e6e369a43299e157c0e7588b636e025a1808a3f5581
|
5
|
-
language: ruby
|
6
|
-
rvm:
|
7
|
-
- 2.2
|
8
|
-
- 2.3
|
9
|
-
env:
|
10
|
-
- DB=mysql
|
11
|
-
- DB=pg
|
12
|
-
services:
|
13
|
-
- postgresql
|
14
|
-
addons:
|
15
|
-
postgresql: "9.4"
|
16
|
-
before_install:
|
17
|
-
- gem i rubygems-update -v '<3' && update_rubygems
|
18
|
-
- gem install bundler -v 1.17.3
|
19
|
-
- gem --version
|
20
|
-
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
21
|
-
- chmod +x ./cc-test-reporter
|
22
|
-
- ./cc-test-reporter before-build
|
23
|
-
before_script:
|
24
|
-
- mysql -V
|
25
|
-
- mysql -u root -e 'CREATE DATABASE travis_ci_test;'
|
26
|
-
- psql -c "SELECT version();"
|
27
|
-
- psql -c 'create database travis_ci_test;' -U postgres
|
28
|
-
gemfile:
|
29
|
-
- gemfiles/3.2.gemfile
|
30
|
-
- gemfiles/4.2.gemfile
|
31
|
-
- gemfiles/5.0.gemfile
|
32
|
-
- gemfiles/5.1.gemfile
|
33
|
-
- gemfiles/5.2.gemfile
|
34
|
-
script:
|
35
|
-
- bundle exec rake test
|
36
|
-
after_script:
|
37
|
-
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|