voltron-encrypt 0.1.7 → 0.1.8
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/lib/voltron/encrypt/version.rb +1 -1
- data/lib/voltron/encryptable.rb +17 -19
- 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: 3d929fa58a1904f7db7ab28386412ce0cc165ff3
|
4
|
+
data.tar.gz: a28c000806c6e26366db1b3be9e8cd372fffb69d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c886e6b8cdbd858244f755418a5b674c77d5a09871c54673013d7e470a716a8521e81c73ec3f3a915fabbfbe42bd769439b08755abeb90a451c598daefc4f72
|
7
|
+
data.tar.gz: 65ca70e0444599a06823308d5dd340d9343c555cbb12313a396ec7ef3ad972f9dd8d478b22a0eeaba68a874a3087e25369cc98ca2645656a7dc7130f948d504b
|
data/lib/voltron/encryptable.rb
CHANGED
@@ -17,25 +17,6 @@ module Voltron
|
|
17
17
|
|
18
18
|
default_scope { joins(:encryptable).includes(:encryptable) }
|
19
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
|
-
|
39
20
|
end
|
40
21
|
|
41
22
|
module ClassMethods
|
@@ -87,6 +68,23 @@ module Voltron
|
|
87
68
|
end
|
88
69
|
|
89
70
|
module InstanceMethods
|
71
|
+
def assign_attributes(new_attributes)
|
72
|
+
belongs = self.class.reflect_on_all_associations(:belongs_to).map { |b| { column: "#{b.name}_id", class_name: (b.options[:class_name] || b.name).to_s.classify } }
|
73
|
+
|
74
|
+
belongs.each do |belong|
|
75
|
+
begin
|
76
|
+
klass = belong[:class_name].safe_constantize
|
77
|
+
value = new_attributes[belong[:column]]
|
78
|
+
next if !klass.has_encrypted_id? || value.blank?
|
79
|
+
record = klass.find(value)
|
80
|
+
new_attributes[belong[:column]] = record.id
|
81
|
+
rescue NameError, ActiveRecord::RecordNotFound
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
super(new_attributes)
|
86
|
+
end
|
87
|
+
|
90
88
|
def to_param
|
91
89
|
return super if encryptable.nil?
|
92
90
|
|
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Hainer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-07 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.4.8
|
188
188
|
signing_key:
|
189
189
|
specification_version: 4
|
190
190
|
summary: Enables base 64 encoded ids on rails models
|