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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 278557400ef5996ade0a48d3e1ebee0a87b33ffd
4
- data.tar.gz: 012b9e1797827875d2233e47379b7cf95d0229f4
3
+ metadata.gz: 97984ca501ece1def3f2b927a3c7e4d7e519d556
4
+ data.tar.gz: 5e2ca443f95e6750cc5452aa3fbbf216c88310fd
5
5
  SHA512:
6
- metadata.gz: 95bd857aabae26567eb21d75844c83545af403a09977be7278ff5814ea40d65917f73195387e8b56bcefed87e498bcea1cc80bdb2da6a66c9546d4957f6f7703
7
- data.tar.gz: 94463817979f129f636ac7a5c7500b1da19c1fc9850783f375609a8cdbd9bf940899d899d8d0940614b6c65cbeebfc313cc9be32d9831f4a35f4b4518d55a848
6
+ metadata.gz: 5f12d70fdbe331cd2d9fad73bfaf5d687c65785ea0edd84e3e761844bef0f587c0bcd4b793bd2c6dae692ce59e46461f21e506b5cb0617e075c0888d4edeb271
7
+ data.tar.gz: 07436ecb8eb310a6f4a3287dfca27004bb79c29d56fc0b9900d43838432b24a1345e0da040c337b9bdb95b46936736f591fa179320f614621cbc2816e359cc35
data/.gitignore CHANGED
@@ -10,4 +10,5 @@ tmp/
10
10
  log/
11
11
  voltron-*.gem
12
12
  *.bak
13
- *.sqlite3
13
+ *.sqlite3
14
+ .byebug_history
data/Gemfile CHANGED
@@ -2,4 +2,4 @@ source 'https://rubygems.org'
2
2
  source 'http://gem.minow.io'
3
3
 
4
4
  # Specify your gem's dependencies in voltron-encrypt.gemspec
5
- gemspec
5
+ gemspec
@@ -1,5 +1,5 @@
1
1
  module Voltron
2
2
  class Encrypt
3
- VERSION = "0.1.6".freeze
3
+ VERSION = "0.1.7".freeze
4
4
  end
5
5
  end
@@ -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(conditions)
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.6
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: 2016-12-19 00:00:00.000000000 Z
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.4.8
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