ensurance 0.1.3 → 0.1.4
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/.gitignore +1 -1
- data/Gemfile.lock +3 -1
- data/README.md +1 -1
- data/ensurance.gemspec +1 -0
- data/lib/ensurance.rb +9 -4
- data/lib/ensurance/version.rb +1 -1
- metadata +22 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f356dd97f450da7e5d90f5f2dd000ae500754f1
|
4
|
+
data.tar.gz: 96489236b803cc22158f1a9a51a68edb6a4e4262
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 269feab585502a890af303f69ff32f4e4623ab524318faa186ec8d81c032f7b3a39927d686be1d3af07a126a6975fc7aa25f641b40274fbee6c73cda552a934f
|
7
|
+
data.tar.gz: '093ec632805684e2134361e8643cb4e1c575d1e586cb79e3b97e2bf74cc34620a45134a1e8dba3853761fba6fd0258724d71668cb66b86e899a0d525bcba1b29'
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ensurance (0.1.
|
4
|
+
ensurance (0.1.3)
|
5
5
|
activesupport (>= 3, < 6)
|
6
6
|
|
7
7
|
GEM
|
@@ -19,6 +19,7 @@ GEM
|
|
19
19
|
minitest (~> 5.1)
|
20
20
|
tzinfo (~> 1.1)
|
21
21
|
arel (8.0.0)
|
22
|
+
awesome_print (1.8.0)
|
22
23
|
concurrent-ruby (1.0.5)
|
23
24
|
diff-lcs (1.3)
|
24
25
|
globalid (0.4.1)
|
@@ -50,6 +51,7 @@ PLATFORMS
|
|
50
51
|
|
51
52
|
DEPENDENCIES
|
52
53
|
activerecord (>= 3, < 6)
|
54
|
+
awesome_print (>= 1.0, < 2)
|
53
55
|
bundler (~> 1.16)
|
54
56
|
ensurance!
|
55
57
|
globalid (>= 0.3.6, < 2)
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ Allows you to ensure you have the class you expect... it's similar to
|
|
6
6
|
result = value.is_a?(Person) ? value : Person.find(value)
|
7
7
|
```
|
8
8
|
|
9
|
-
You can add fields to "ensure_by" (
|
9
|
+
You can add fields to "ensure_by" (`self.primary_key` is the default)
|
10
10
|
e.g.
|
11
11
|
|
12
12
|
if you add `ensure_by :token` to the User class
|
data/ensurance.gemspec
CHANGED
@@ -38,5 +38,6 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.add_development_dependency "activerecord", '>= 3', '< 6'
|
39
39
|
spec.add_development_dependency "globalid", '>= 0.3.6', '< 2'
|
40
40
|
spec.add_development_dependency "sqlite3", '>= 1.3.0', '< 4'
|
41
|
+
spec.add_development_dependency "awesome_print", '>= 1.0', '< 2'
|
41
42
|
end
|
42
43
|
|
data/lib/ensurance.rb
CHANGED
@@ -16,9 +16,12 @@ module Ensurance
|
|
16
16
|
|
17
17
|
def ensure(thing = nil)
|
18
18
|
return nil unless thing.present?
|
19
|
+
found = nil
|
19
20
|
|
20
21
|
if thing.is_a?(self)
|
21
22
|
return thing
|
23
|
+
elsif thing.is_a?(Array)
|
24
|
+
raise ArgumentError.new("Cannot Ensure #{self.name} with an Array: #{thing.inspect}")
|
22
25
|
elsif thing.is_a?(GlobalID)
|
23
26
|
return GlobalID::Locator.locate(thing)
|
24
27
|
elsif thing.is_a?(Hash) && thing['_aj_globalid'] && (found = GlobalID::Locator.locate(thing['_aj_globalid']))
|
@@ -26,12 +29,14 @@ module Ensurance
|
|
26
29
|
elsif thing.is_a?(String) && found = GlobalID::Locator.locate(thing)
|
27
30
|
return found
|
28
31
|
end
|
29
|
-
found = nil
|
30
32
|
|
31
|
-
@_ensure_by ||= [self.primary_key
|
33
|
+
@_ensure_by ||= [@_additional_ensure_by || self.primary_key].flatten.compact.uniq
|
32
34
|
@_ensure_by.each do |ensure_field|
|
33
|
-
value = thing
|
34
|
-
|
35
|
+
value = thing
|
36
|
+
if thing.is_a?(Hash)
|
37
|
+
value = thing.fetch(ensure_field.to_sym, nil) || thing.fetch(ensure_field.to_s, nil)
|
38
|
+
end
|
39
|
+
found = self.find_by(ensure_field => value) if value.present? && !value.is_a?(Hash)
|
35
40
|
break if found.is_a?(self)
|
36
41
|
end
|
37
42
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Sharpe
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -132,6 +132,26 @@ dependencies:
|
|
132
132
|
- - "<"
|
133
133
|
- !ruby/object:Gem::Version
|
134
134
|
version: '4'
|
135
|
+
- !ruby/object:Gem::Dependency
|
136
|
+
name: awesome_print
|
137
|
+
requirement: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '1.0'
|
142
|
+
- - "<"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '2'
|
145
|
+
type: :development
|
146
|
+
prerelease: false
|
147
|
+
version_requirements: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '1.0'
|
152
|
+
- - "<"
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '2'
|
135
155
|
description: 'A handy shortcut for user = user.is_a?(User) ? user : User.find(user)'
|
136
156
|
email:
|
137
157
|
- bsharpe@gmail.com
|
@@ -149,7 +169,6 @@ files:
|
|
149
169
|
- Rakefile
|
150
170
|
- bin/console
|
151
171
|
- bin/setup
|
152
|
-
- ensurance-0.1.0.gem
|
153
172
|
- ensurance.gemspec
|
154
173
|
- lib/ensurance.rb
|
155
174
|
- lib/ensurance/date_ensure.rb
|