ensurance 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +20 -8
- data/lib/ensurance/array_ensure.rb +1 -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: f9bfedd99e51ab369010ddd9c2ccf5281da7420da68de1e7656f1fbca6cbab7b
|
4
|
+
data.tar.gz: b43dc62d2a39d09d940d8c65ffd0c260b90303b8a4f30862c04cb708f8875d34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4231f5b79d2dd8c31c7cccead490173bc3e294864d1e0c245da9184848cefcbc234721d1bf36f35c227a12b7fbfafaf7918889312788de7c40403a6d69b409da
|
7
|
+
data.tar.gz: ad3dec83ad4b66b59a18c8adb0155e5b65c1a31c5ada7b3e4adda50e46df436a2ea25702406dfa14b30d57811c616abf3606d93923fd66742fa6257a8464f497
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -54,21 +54,32 @@ In this way you can call it with a User object, or a user `id` and it works just
|
|
54
54
|
Also adds ensurance features to `Hash`, `Time`, and `Date`
|
55
55
|
|
56
56
|
```
|
57
|
+
Time.ensure(nil) -> nil
|
57
58
|
Time.ensure(Date.today) -> Date.today.beginning_of_day
|
58
59
|
Time.ensure(1509556285) -> 2017-11-01 11:11:25 -0600
|
59
60
|
Time.ensure("1509556285") -> 2017-11-01 11:11:25 -0600
|
60
61
|
Time.ensure(DateTime.now) -> DateTime.now.to_time
|
61
|
-
Time.ensure(nil) -> nil
|
62
62
|
Time.ensure(1..4) -> ArgumentError "Unhandled Type for Time to ensure: Range"
|
63
|
+
Time.ensure(Time.now.to_s) -> Time.now [uses Time.parse()]
|
64
|
+
Time.ensure(Time.now.iso8601) -> Time.now [uses Time.parse()]
|
63
65
|
|
64
|
-
Date.ensure(Date.today) -> Date.today
|
65
66
|
Date.ensure(nil) -> nil
|
67
|
+
Date.ensure(Date.today) -> Date.today
|
66
68
|
Date.ensure(1509556285) -> 2017-11-01
|
69
|
+
Date.ensure("1509556285") -> 2017-11-01
|
70
|
+
Date.ensure("2017-11-01") -> 2017-11-01 [uses Date.parse()]
|
71
|
+
Date.ensure("11/01/2017") -> 2017-11-01 [uses Date.parse()]
|
67
72
|
|
73
|
+
Hash.ensure(nil) -> nil
|
68
74
|
Hash.ensure(<aHash>) -> <aHash>
|
69
75
|
Hash.ensure(<json_string>) -> Hash
|
70
|
-
Hash.ensure(nil) -> nil
|
71
76
|
Hash.ensure(<an array>) -> <an array>.to_h
|
77
|
+
|
78
|
+
Array.ensure(nil) -> nil
|
79
|
+
Array.ensure([]) -> []
|
80
|
+
Array.ensure("1,2,4") -> ["1","2","4"]
|
81
|
+
Array.ensure("[1,2,4]") -> [1,2,4] (JSON string)
|
82
|
+
Array.ensure({a:1, b:2}) -> [[:a, 1], [:b, 2]]
|
72
83
|
```
|
73
84
|
|
74
85
|
### ActiveRecord
|
@@ -79,16 +90,17 @@ You can specify another field or fields to ensure by doing the following:
|
|
79
90
|
class User < ApplicationRecord
|
80
91
|
include Ensurance
|
81
92
|
|
82
|
-
ensure_by :token <- totally optional
|
93
|
+
ensure_by :id, :token <- totally optional (:id is the default)
|
83
94
|
end
|
84
95
|
|
85
|
-
User.ensure(
|
86
|
-
User.ensure(
|
96
|
+
User.ensure(nil) -> nil
|
97
|
+
User.ensure!(nil) -> nil
|
98
|
+
User.ensure!(1) == User.find(1)
|
99
|
+
User.ensure(1) == User.find_by_id(1)
|
100
|
+
User.ensure(<a user record>) -> <a user record> (nothing happens)
|
87
101
|
User.ensure(<globalid>) == GlobalID::Locator.locate(<globalid>)
|
88
102
|
User.ensure(<globalid string>) == GlobalID::Locator.locate(<globalid string>)
|
89
103
|
User.ensure(<some token>) == User.where(token: <some token>).first
|
90
|
-
User.ensure(nil) -> nil
|
91
|
-
User.ensure!(nil) -> nil
|
92
104
|
User.ensure!(<unknown_id>) -> ActiveRecord::RecordNotFound
|
93
105
|
```
|
94
106
|
|
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.14
|
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-
|
11
|
+
date: 2018-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|