voltron-encrypt 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 +2 -1
- data/lib/voltron/encrypt/active_record/collection_association.rb +37 -0
- data/lib/voltron/encrypt/engine.rb +1 -0
- data/lib/voltron/encrypt/version.rb +1 -1
- data/lib/voltron/encrypt.rb +9 -8
- data/lib/voltron/encryptable.rb +9 -1
- data/voltron-encrypt.gemspec +1 -0
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bec1a7a6c6807648a8bb6e1debc10e4d098bc45
|
4
|
+
data.tar.gz: a1b95933e6526a729d390bff947d0b43bf3ffb39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5b2737a2169939aa466511a8753918a8cf65adde2cabe0cbd9099895d8ac46fd2aa0b03cef14300e5d0661fc8e07c9016b71f92965392902aa43609d9c0baf3
|
7
|
+
data.tar.gz: ac229008eb3831e1fabb5f92244c33d5602339f6fee7f636405a84bc3ca65ac9abe3881bd1ebf0652501aeb90fd39a9ab91177e606f7f70c5edaa5c886c3b215
|
data/.gitignore
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Voltron
|
2
|
+
class Encrypt
|
3
|
+
module ActiveRecord
|
4
|
+
module CollectionAssociation
|
5
|
+
|
6
|
+
def ids_writer(ids)
|
7
|
+
if klass.has_encrypted_id?
|
8
|
+
ids.reject!(&:blank?)
|
9
|
+
replace(klass.find(ids))
|
10
|
+
else
|
11
|
+
super ids
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def ids_reader
|
16
|
+
if loaded?
|
17
|
+
load_target.map do |record|
|
18
|
+
if klass.has_encrypted_id?
|
19
|
+
record.to_param
|
20
|
+
else
|
21
|
+
record.send(reflection.association_primary_key)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
else
|
25
|
+
if klass.has_encrypted_id?
|
26
|
+
scope.map(&:to_param)
|
27
|
+
else
|
28
|
+
column = "#{reflection.quoted_table_name}.#{reflection.association_primary_key}"
|
29
|
+
scope.pluck(column)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -6,6 +6,7 @@ module Voltron
|
|
6
6
|
|
7
7
|
initializer "voltron.encrypt.initialize" do
|
8
8
|
::ActiveRecord::Base.send :extend, ::Voltron::Encryptable
|
9
|
+
::ActiveRecord::Associations::CollectionAssociation.send :prepend, ::Voltron::Encrypt::ActiveRecord::CollectionAssociation
|
9
10
|
|
10
11
|
# Corrects sidekiq resource lookup by forcing it to find_by_id rather than find with the model id
|
11
12
|
# We either want it to find with to_param value, or find_by_id with the actual id, this is the latter
|
data/lib/voltron/encrypt.rb
CHANGED
@@ -2,6 +2,7 @@ require "voltron"
|
|
2
2
|
require "voltron/encrypt/version"
|
3
3
|
require "voltron/config/encrypt"
|
4
4
|
require "voltron/encryptable"
|
5
|
+
require "voltron/encrypt/active_record/collection_association"
|
5
6
|
|
6
7
|
module Voltron
|
7
8
|
class Encrypt
|
@@ -49,15 +50,15 @@ module Voltron
|
|
49
50
|
!blacklist(encoded.length).match(regex).nil?
|
50
51
|
end
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
else
|
58
|
-
""
|
59
|
-
end
|
53
|
+
def blacklist(len = 6)
|
54
|
+
if File.exist?(Voltron.config.encrypt.blacklist.to_s)
|
55
|
+
File.readlines(Voltron.config.encrypt.blacklist).map(&:strip).reject { |line| line.length > len }.join(" ")
|
56
|
+
else
|
57
|
+
""
|
60
58
|
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
61
62
|
|
62
63
|
def translations
|
63
64
|
{
|
data/lib/voltron/encryptable.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
module Voltron
|
2
2
|
module Encryptable
|
3
3
|
|
4
|
+
def has_encrypted_id?
|
5
|
+
false
|
6
|
+
end
|
7
|
+
|
4
8
|
def encrypted_id
|
5
9
|
extend ClassMethods
|
6
10
|
include InstanceMethods
|
@@ -13,6 +17,10 @@ module Voltron
|
|
13
17
|
end
|
14
18
|
|
15
19
|
module ClassMethods
|
20
|
+
def has_encrypted_id?
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
16
24
|
def find(*args)
|
17
25
|
scope = args.slice!(0)
|
18
26
|
options = args.slice!(0) || {}
|
@@ -20,7 +28,7 @@ module Voltron
|
|
20
28
|
if !options[:bypass] && ![:first, :last, :all].include?(scope.try(:to_sym))
|
21
29
|
scope = decoded_ids(scope)
|
22
30
|
end
|
23
|
-
|
31
|
+
|
24
32
|
super(scope)
|
25
33
|
end
|
26
34
|
|
data/voltron-encrypt.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency "rails", ">= 4.2"
|
22
22
|
spec.add_dependency "voltron", ">= 0.1.0"
|
23
23
|
|
24
|
+
spec.add_development_dependency "byebug"
|
24
25
|
spec.add_development_dependency "bundler", ">= 1.12"
|
25
26
|
spec.add_development_dependency "rake", ">= 10.0"
|
26
27
|
spec.add_development_dependency "rspec", ">= 3.0"
|
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.4
|
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-
|
11
|
+
date: 2016-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.1.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -145,6 +159,7 @@ files:
|
|
145
159
|
- lib/generators/voltron/encrypt/install_generator.rb
|
146
160
|
- lib/voltron/config/encrypt.rb
|
147
161
|
- lib/voltron/encrypt.rb
|
162
|
+
- lib/voltron/encrypt/active_record/collection_association.rb
|
148
163
|
- lib/voltron/encrypt/engine.rb
|
149
164
|
- lib/voltron/encrypt/version.rb
|
150
165
|
- lib/voltron/encryptable.rb
|
@@ -169,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
184
|
version: '0'
|
170
185
|
requirements: []
|
171
186
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.
|
187
|
+
rubygems_version: 2.5.1
|
173
188
|
signing_key:
|
174
189
|
specification_version: 4
|
175
190
|
summary: Enables base 64 encoded ids on rails models
|