ensurance 0.1.18 → 0.1.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +12 -12
- data/lib/ensurance/date_ensure.rb +6 -3
- data/lib/ensurance/time_ensure.rb +7 -4
- data/lib/ensurance/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ac8c082d86cf0bde5f2b23ca40b89cce7a4641ed8f57778c79a1a848a02ab82
|
4
|
+
data.tar.gz: 1bd231f16ab432a4c5c66058e9f9dde2fa532329863ca92e1b1778b80cfc3466
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab06cec4700be175341d53d82d879056984502327b83d76414d36ed85aa0a1bb49b2051c82cb9c847fa8227a4b156483b0e989d82743300a86d5e98205dbe46b
|
7
|
+
data.tar.gz: 3874f44a84344ccb8de3fcef1153bd4ffa259b2d8f8b9ac3c1665e147d307de020e55341d5edacf632f02ab039322502f0c2eb7a816da7036cdc08b461a315cb
|
data/CHANGELOG.md
ADDED
data/Gemfile.lock
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ensurance (0.1.
|
4
|
+
ensurance (0.1.18)
|
5
5
|
activesupport (>= 3, < 6)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (5.2.
|
11
|
-
activesupport (= 5.2.
|
12
|
-
activerecord (5.2.
|
13
|
-
activemodel (= 5.2.
|
14
|
-
activesupport (= 5.2.
|
10
|
+
activemodel (5.2.2)
|
11
|
+
activesupport (= 5.2.2)
|
12
|
+
activerecord (5.2.2)
|
13
|
+
activemodel (= 5.2.2)
|
14
|
+
activesupport (= 5.2.2)
|
15
15
|
arel (>= 9.0)
|
16
|
-
activesupport (5.2.
|
16
|
+
activesupport (5.2.2)
|
17
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
18
|
i18n (>= 0.7, < 2)
|
19
19
|
minitest (~> 5.1)
|
20
20
|
tzinfo (~> 1.1)
|
21
21
|
arel (9.0.0)
|
22
22
|
awesome_print (1.8.0)
|
23
|
-
concurrent-ruby (1.
|
23
|
+
concurrent-ruby (1.1.4)
|
24
24
|
diff-lcs (1.3)
|
25
|
-
globalid (0.4.
|
25
|
+
globalid (0.4.2)
|
26
26
|
activesupport (>= 4.2.0)
|
27
|
-
i18n (1.
|
27
|
+
i18n (1.5.2)
|
28
28
|
concurrent-ruby (~> 1.0)
|
29
29
|
minitest (5.11.3)
|
30
30
|
rake (10.5.0)
|
@@ -34,7 +34,7 @@ GEM
|
|
34
34
|
rspec-mocks (~> 3.8.0)
|
35
35
|
rspec-core (3.8.0)
|
36
36
|
rspec-support (~> 3.8.0)
|
37
|
-
rspec-expectations (3.8.
|
37
|
+
rspec-expectations (3.8.2)
|
38
38
|
diff-lcs (>= 1.2.0, < 2.0)
|
39
39
|
rspec-support (~> 3.8.0)
|
40
40
|
rspec-mocks (3.8.0)
|
@@ -60,4 +60,4 @@ DEPENDENCIES
|
|
60
60
|
sqlite3 (>= 1.3.0, < 4)
|
61
61
|
|
62
62
|
BUNDLED WITH
|
63
|
-
1.
|
63
|
+
1.17.3
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# NOTE: https://blog.daveallie.com/clean-monkey-patching/
|
2
2
|
|
3
3
|
require 'active_support/core_ext/date'
|
4
|
+
require 'active_support/core_ext/time'
|
4
5
|
|
5
6
|
module Ensurance
|
6
7
|
module DateEnsure
|
@@ -11,6 +12,8 @@ module Ensurance
|
|
11
12
|
module ClassMethods
|
12
13
|
DATE_ENSURE_FORMATS = %w[%m/%d/%Y %Y/%m/%d].freeze
|
13
14
|
def ensure(thing)
|
15
|
+
Time.zone ||= 'UTC'
|
16
|
+
|
14
17
|
case thing.class.name
|
15
18
|
when 'NilClass'
|
16
19
|
nil
|
@@ -20,9 +23,9 @@ module Ensurance
|
|
20
23
|
thing
|
21
24
|
when 'String'
|
22
25
|
if thing.to_i.to_s == thing
|
23
|
-
::Time.at(thing.to_i).to_date
|
26
|
+
::Time.zone.at(thing.to_i).to_date
|
24
27
|
elsif thing.to_f.to_s == thing
|
25
|
-
::Time.at(thing.to_f).to_date
|
28
|
+
::Time.zone.at(thing.to_f).to_date
|
26
29
|
elsif thing.index('/')
|
27
30
|
# Assume US Date format
|
28
31
|
result = nil
|
@@ -36,7 +39,7 @@ module Ensurance
|
|
36
39
|
raise ArgumentError, "Bad Date: #{thing}".yellow unless result
|
37
40
|
result
|
38
41
|
else
|
39
|
-
::
|
42
|
+
::Time.zone.parse(thing).to_date
|
40
43
|
end
|
41
44
|
else
|
42
45
|
if thing.respond_to?(:to_date)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'active_support/core_ext/time'
|
2
|
+
require 'active_support/time_with_zone'
|
2
3
|
|
3
4
|
# NOTE: https://blog.daveallie.com/clean-monkey-patching/
|
4
5
|
|
@@ -10,6 +11,8 @@ module Ensurance
|
|
10
11
|
|
11
12
|
module ClassMethods
|
12
13
|
def ensure(thing)
|
14
|
+
::Time.zone ||= "UTC"
|
15
|
+
|
13
16
|
case thing.class.name
|
14
17
|
when 'NilClass'
|
15
18
|
thing
|
@@ -18,14 +21,14 @@ module Ensurance
|
|
18
21
|
when 'Date'
|
19
22
|
thing.beginning_of_day
|
20
23
|
when 'Integer', 'Float'
|
21
|
-
::Time.at(thing)
|
24
|
+
::Time.zone.at(thing)
|
22
25
|
when 'String'
|
23
26
|
if thing.to_i.to_s == thing
|
24
|
-
::Time.at(thing.to_i)
|
27
|
+
::Time.zone.at(thing.to_i)
|
25
28
|
elsif thing.to_f.to_s == thing
|
26
|
-
::Time.at(thing.to_f)
|
29
|
+
::Time.zone.at(thing.to_f)
|
27
30
|
else
|
28
|
-
::Time.parse(thing)
|
31
|
+
::Time.zone.parse(thing)
|
29
32
|
end
|
30
33
|
else
|
31
34
|
if thing.respond_to?(:to_time)
|
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.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Sharpe
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -162,6 +162,7 @@ files:
|
|
162
162
|
- ".gitignore"
|
163
163
|
- ".rspec"
|
164
164
|
- ".travis.yml"
|
165
|
+
- CHANGELOG.md
|
165
166
|
- Gemfile
|
166
167
|
- Gemfile.lock
|
167
168
|
- LICENSE.txt
|