find_with_order 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -1
- data/find_with_order.gemspec +2 -2
- data/lib/find_with_order.rb +1 -1
- data/lib/find_with_order/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db2431c776b7124cdaa2e01efd6ec12bfdc1d513
|
4
|
+
data.tar.gz: 68f959361cc19eb381f94eb82028502f09b6f0f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbe7b8e24e8afe6f51869f3dbac286f6361485b10229aa436ac395e69b6882291486747c6ea8d560650dff25e79bb59c0de577c20b49f12862f1c0caabc913da
|
7
|
+
data.tar.gz: 65080703b7bc52021f0e8096af1a591360afb238858761debc0e368b54e761c7061b36b23a7ec54ea53a8e51b81be166955a9d79d67df7232d66014d52f62ac3
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
# FindWithOrder
|
8
8
|
|
9
|
-
|
9
|
+
Find records in the same order of input array.
|
10
10
|
|
11
11
|
## Installation
|
12
12
|
|
@@ -43,6 +43,16 @@ User.where_with_order(:name, %w(Pearl John Kathenrie)).pluck(:name)
|
|
43
43
|
# => ['Pearl', 'John', 'Kathenrie']
|
44
44
|
```
|
45
45
|
|
46
|
+
## Benchmark
|
47
|
+
|
48
|
+
```
|
49
|
+
user system total real
|
50
|
+
Find with order 0.030000 0.000000 0.030000 ( 0.033517)
|
51
|
+
Find then sort by index 1.510000 0.030000 1.540000 ( 1.706246)
|
52
|
+
Find then sort by hash mapping 1.120000 0.010000 1.130000 ( 1.192891)
|
53
|
+
```
|
54
|
+
[test script](https://github.com/khiav223577/find_with_order/issues/4)
|
55
|
+
|
46
56
|
## Development
|
47
57
|
|
48
58
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/find_with_order.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["khiav reoy"]
|
10
10
|
spec.email = ["mrtmrt15xn@yahoo.com.tw"]
|
11
11
|
|
12
|
-
spec.summary = %q{
|
13
|
-
spec.description = %q{
|
12
|
+
spec.summary = %q{A simple way to find records in the same order of input array.}
|
13
|
+
spec.description = %q{A simple way to find records in the same order of input array. Has better performance than manually sorting. Supports Rails 3+.}
|
14
14
|
spec.homepage = "https://github.com/khiav223577/find_with_order"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
data/lib/find_with_order.rb
CHANGED
@@ -5,7 +5,7 @@ class << ActiveRecord::Base
|
|
5
5
|
def find_with_order(ids)
|
6
6
|
return none if ids.blank?
|
7
7
|
ids = ids.uniq
|
8
|
-
return where(id: ids).order("field(id, #{ids.join(',')})").to_a
|
8
|
+
return where(id: ids).order("field(#{table_name}.id, #{ids.join(',')})").to_a
|
9
9
|
end
|
10
10
|
def where_with_order(column, ids)
|
11
11
|
return none if ids.blank?
|
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.0.
|
4
|
+
version: 1.0.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: 2017-
|
11
|
+
date: 2017-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,7 +80,8 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0.3'
|
83
|
-
description:
|
83
|
+
description: A simple way to find records in the same order of input array. Has better
|
84
|
+
performance than manually sorting. Supports Rails 3+.
|
84
85
|
email:
|
85
86
|
- mrtmrt15xn@yahoo.com.tw
|
86
87
|
executables: []
|
@@ -124,5 +125,5 @@ rubyforge_project:
|
|
124
125
|
rubygems_version: 2.6.8
|
125
126
|
signing_key:
|
126
127
|
specification_version: 4
|
127
|
-
summary:
|
128
|
+
summary: A simple way to find records in the same order of input array.
|
128
129
|
test_files: []
|