ensurance 0.1.14 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -1
- data/lib/ensurance.rb +2 -1
- data/lib/ensurance/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9dc0cb170529eaf783a26f087ee9a64c47403a7a881b098fed4417b6d289c78a
|
4
|
+
data.tar.gz: 5663a75b82064550e92d3c57ed89d508fb8c5186e78e27fa9ef73f25c3599282
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 :
|
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
|
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
|
data/lib/ensurance/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2018-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|