ensurance 0.1.14 → 0.1.15

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
  SHA256:
3
- metadata.gz: f9bfedd99e51ab369010ddd9c2ccf5281da7420da68de1e7656f1fbca6cbab7b
4
- data.tar.gz: b43dc62d2a39d09d940d8c65ffd0c260b90303b8a4f30862c04cb708f8875d34
3
+ metadata.gz: 9dc0cb170529eaf783a26f087ee9a64c47403a7a881b098fed4417b6d289c78a
4
+ data.tar.gz: 5663a75b82064550e92d3c57ed89d508fb8c5186e78e27fa9ef73f25c3599282
5
5
  SHA512:
6
- metadata.gz: 4231f5b79d2dd8c31c7cccead490173bc3e294864d1e0c245da9184848cefcbc234721d1bf36f35c227a12b7fbfafaf7918889312788de7c40403a6d69b409da
7
- data.tar.gz: ad3dec83ad4b66b59a18c8adb0155e5b65c1a31c5ada7b3e4adda50e46df436a2ea25702406dfa14b30d57811c616abf3606d93923fd66742fa6257a8464f497
6
+ metadata.gz: b81c806ee2c6b15a527565f68d88bc2925f0548b023cd0bc9eaf7e7dacaf9510191a9ef2e7cd1797b8c3a62b5f35abd476abf19f37f67bd841969529bd82c6b3
7
+ data.tar.gz: 431dd8252c904e563cf7d69a31a42d095d4cd4576104e81e38c33d0d60502f4f03886065194a36c1dcef87d65ef9e2476ae98df310ee3653d7ce50995c568341
data/README.md CHANGED
@@ -90,7 +90,7 @@ You can specify another field or fields to ensure by doing the following:
90
90
  class User < ApplicationRecord
91
91
  include Ensurance
92
92
 
93
- ensure_by :id, :token <- totally optional (:id is the default)
93
+ ensure_by :token, :id <- totally optional (:id is the default)
94
94
  end
95
95
 
96
96
  User.ensure(nil) -> nil
@@ -104,6 +104,11 @@ User.ensure(<some token>) == User.where(token: <some token>).first
104
104
  User.ensure!(<unknown_id>) -> ActiveRecord::RecordNotFound
105
105
  ```
106
106
 
107
+ #### Note:
108
+ - They are checked in the order you provide them. (`token` first, then `id`)
109
+ - if using something other than a unique field, it returns the most recently created_one (using `created_at`)
110
+
111
+
107
112
  ## Contributing
108
113
 
109
114
  Bug reports and pull requests are welcome on GitHub at https://github.com/bsharpe/ensurance.
data/lib/ensurance.rb CHANGED
@@ -41,7 +41,8 @@ module Ensurance
41
41
  end
42
42
  if ensure_field.to_sym == :id
43
43
  begin
44
- record = find(value)
44
+ # Always return the most recent record that matches
45
+ record = where(ensure_field => value).order(created_at: :desc).first
45
46
  rescue ActiveRecord::RecordNotFound
46
47
  nil
47
48
  end
@@ -1,3 +1,3 @@
1
1
  module Ensurance
2
- VERSION = '0.1.14'.freeze
2
+ VERSION = '0.1.15'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ensurance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Sharpe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-29 00:00:00.000000000 Z
11
+ date: 2018-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport