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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97984ca501ece1def3f2b927a3c7e4d7e519d556
4
- data.tar.gz: 5e2ca443f95e6750cc5452aa3fbbf216c88310fd
3
+ metadata.gz: 3d929fa58a1904f7db7ab28386412ce0cc165ff3
4
+ data.tar.gz: a28c000806c6e26366db1b3be9e8cd372fffb69d
5
5
  SHA512:
6
- metadata.gz: 5f12d70fdbe331cd2d9fad73bfaf5d687c65785ea0edd84e3e761844bef0f587c0bcd4b793bd2c6dae692ce59e46461f21e506b5cb0617e075c0888d4edeb271
7
- data.tar.gz: 07436ecb8eb310a6f4a3287dfca27004bb79c29d56fc0b9900d43838432b24a1345e0da040c337b9bdb95b46936736f591fa179320f614621cbc2816e359cc35
6
+ metadata.gz: 7c886e6b8cdbd858244f755418a5b674c77d5a09871c54673013d7e470a716a8521e81c73ec3f3a915fabbfbe42bd769439b08755abeb90a451c598daefc4f72
7
+ data.tar.gz: 65ca70e0444599a06823308d5dd340d9343c555cbb12313a396ec7ef3ad972f9dd8d478b22a0eeaba68a874a3087e25369cc98ca2645656a7dc7130f948d504b
@@ -1,5 +1,5 @@
1
1
  module Voltron
2
2
  class Encrypt
3
- VERSION = "0.1.7".freeze
3
+ VERSION = "0.1.8".freeze
4
4
  end
5
5
  end
@@ -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.7
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-03 00:00:00.000000000 Z
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.6.6
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