ordered_find 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64f9d7716a066605c80abd3bf32154361694a6aa
4
- data.tar.gz: de0efc60fbef9d0f872f4d01352969918969ee63
3
+ metadata.gz: 8db52972af2ac666d8c341da6f9bbb0cfe857ac8
4
+ data.tar.gz: 2a4cc1bbafec2dbb47574720571026b29f90cbbc
5
5
  SHA512:
6
- metadata.gz: 09da21b5ce1c369428a926a849bafb8c3f48e48745367000c04e208b00d768eb1a675c418c60bc14a04118150b3e4eae7f294af32f7a3512c899d35280d9d689
7
- data.tar.gz: 1db7491c30feeab7ccdbfe98d6ea29d49af301a2c1ff10edc7dc7048bbb9bc3a12180e404416a74d96f29a89a4f6b27059ab852b9f5a394a99115194f575666a
6
+ metadata.gz: 14061d0a4601dba1dcd09377e8938da0e8d854b0f634ad3f7337047c32a3365320218c34f26283538c391abf1a9ce1f06fe918469d58dc7e0a63cab24db7e02d
7
+ data.tar.gz: 0795f2a1e7865092c20a6bbcc492e68af0d5e829fa11ff94b4566213452662096f4b1391bcb06089a0212dee157bb234a88cfb2fedf23ed33153c5576ac757cc
data/README.md CHANGED
@@ -19,14 +19,25 @@ Or install it yourself as:
19
19
  ## Usage
20
20
 
21
21
  ```
22
- SomeModel.ordered_find([1, 3, 2])
23
- => [#<SomeModel id: 1>, #<SomeModel id: 3>, #<SomeModel id: 2>]
22
+ SomeModel.ordered_find([1, 3, 2, 1])
23
+ => [#<SomeModel id: 1>, #<SomeModel id: 3>, #<SomeModel id: 2>, #<SomeModel id: 1>]
24
24
  ```
25
25
  or
26
26
  ```
27
27
  SomeModel.ordered_find(1, 3, 2)
28
28
  ```
29
29
 
30
+ ```
31
+ SomeModel.ordered_find([1, 3, 2, nil, 1])
32
+ => raise ActiveRecord::RecordNotFound
33
+ ```
34
+
35
+ ```
36
+ SomeModel.ordered_find_by_id([1, 3, 2, nil, 1])
37
+ => [#<SomeModel id: 1>, #<SomeModel id: 3>, #<SomeModel id: 2>, nil, #<SomeModel id: 1>]
38
+ ```
39
+
40
+
30
41
  ## Contributing
31
42
 
32
43
  1. Fork it ( https://github.com/tkeo/ordered_find/fork )
data/lib/ordered_find.rb CHANGED
@@ -5,13 +5,19 @@ module ActiveRecord
5
5
  class Relation
6
6
  def ordered_find(*args)
7
7
  ids = args.flatten
8
- where(id: ids).sort_by {|object| ids.index(object.id) }
8
+ find(ids.uniq).index_by(&:id).values_at(*ids)
9
+ end
10
+
11
+ def ordered_find_by_id(*args)
12
+ ids = args.flatten
13
+ where(id: ids.uniq).index_by(&:id).values_at(*ids)
9
14
  end
10
15
  end
11
16
 
12
17
  class Base
13
18
  class << self
14
19
  delegate :ordered_find, to: :all
20
+ delegate :ordered_find_by_id, to: :all
15
21
  end
16
22
  end
17
23
  end
@@ -1,3 +1,3 @@
1
1
  module OrderedFind
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/ordered_find.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["takeofujita@gmail.com"]
11
11
  spec.summary = %q{ordered find}
12
12
  spec.description = %q{ordered find}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/tkeo/ordered_find"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ordered_find
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takeo Fujita
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-20 00:00:00.000000000 Z
11
+ date: 2014-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -67,7 +67,7 @@ files:
67
67
  - lib/ordered_find.rb
68
68
  - lib/ordered_find/version.rb
69
69
  - ordered_find.gemspec
70
- homepage: ''
70
+ homepage: https://github.com/tkeo/ordered_find
71
71
  licenses:
72
72
  - MIT
73
73
  metadata: {}