voltron-encrypt 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/Gemfile +1 -1
- data/lib/voltron/encrypt/version.rb +1 -1
- data/lib/voltron/encryptable.rb +23 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97984ca501ece1def3f2b927a3c7e4d7e519d556
|
4
|
+
data.tar.gz: 5e2ca443f95e6750cc5452aa3fbbf216c88310fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f12d70fdbe331cd2d9fad73bfaf5d687c65785ea0edd84e3e761844bef0f587c0bcd4b793bd2c6dae692ce59e46461f21e506b5cb0617e075c0888d4edeb271
|
7
|
+
data.tar.gz: 07436ecb8eb310a6f4a3287dfca27004bb79c29d56fc0b9900d43838432b24a1345e0da040c337b9bdb95b46936736f591fa179320f614621cbc2816e359cc35
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/lib/voltron/encryptable.rb
CHANGED
@@ -14,6 +14,28 @@ module Voltron
|
|
14
14
|
before_create do
|
15
15
|
self.build_encryptable id: find_id
|
16
16
|
end
|
17
|
+
|
18
|
+
default_scope { joins(:encryptable).includes(:encryptable) }
|
19
|
+
|
20
|
+
after_initialize do
|
21
|
+
self.class.reflect_on_all_associations(:belongs_to).each do |belongs|
|
22
|
+
|
23
|
+
# Override the attribute setter method, intercept any value and try and find it by
|
24
|
+
# it's encrypted id. We're assuming the ids passed in the params are encrypted since
|
25
|
+
# our model is using an encrypted id
|
26
|
+
self.class.send(:define_method, "#{belongs.name}_id=") do |val|
|
27
|
+
begin
|
28
|
+
klass = (belongs.options[:class_name] || belongs.name).to_s.classify.constantize
|
29
|
+
return super(val) unless klass.has_encrypted_id?
|
30
|
+
record = klass.find(val)
|
31
|
+
super(record.id)
|
32
|
+
rescue NameError, ActiveRecord::RecordNotFound
|
33
|
+
super(val)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
17
39
|
end
|
18
40
|
|
19
41
|
module ClassMethods
|
@@ -38,7 +60,7 @@ module Voltron
|
|
38
60
|
super(decoded_ids(conditions))
|
39
61
|
else
|
40
62
|
# Otherwise do what exists? normally does
|
41
|
-
super
|
63
|
+
super
|
42
64
|
end
|
43
65
|
end
|
44
66
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: voltron-encrypt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Hainer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -184,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
184
|
version: '0'
|
185
185
|
requirements: []
|
186
186
|
rubyforge_project:
|
187
|
-
rubygems_version: 2.
|
187
|
+
rubygems_version: 2.6.6
|
188
188
|
signing_key:
|
189
189
|
specification_version: 4
|
190
190
|
summary: Enables base 64 encoded ids on rails models
|