secret_id 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/secret_id/active_record.rb +64 -24
- data/lib/secret_id/version.rb +1 -1
- data/lib/secret_id.rb +2 -1
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +5 -0
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22426a2a8d1ef1c2ed9c35ff962eace9b592542b
|
4
|
+
data.tar.gz: 82119fac8f3d6d44f65fe454c19d85fbb0f71cfa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f26076e4beb8babc92d7463f2e275f22f0adee2bdb2537ff0f3946348925f8fad073d64c6b48645c330ca28bc87faebf226b9636b8c7e1102cd38fcb10a7b281
|
7
|
+
data.tar.gz: dc7aefb65671c6c340f3a43781d2ea33b658ba58485035cc518dccc25b0156cd5b1d5b76a03c23d1f19ab5252504c20645904ff084e53a484b6a67c104dee9db
|
@@ -1,44 +1,84 @@
|
|
1
1
|
module SecretId
|
2
2
|
module ActiveRecord
|
3
|
-
|
3
|
+
module FinderMethods
|
4
|
+
extend ActiveSupport::Concern
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
included do
|
7
|
+
# Override ActiveRecord::FinderMethods#find_with_ids decoding ids
|
8
|
+
def find_with_ids(*ids)
|
9
|
+
return super unless @klass.is_a?(SecretId)
|
9
10
|
|
10
|
-
|
11
|
+
unless ids.length == 1
|
12
|
+
options = ids.slice!(ids.size - 1) if ids.last.kind_of?(Hash)
|
13
|
+
options ||= {}
|
14
|
+
|
15
|
+
return super if options[:secret_id] === false
|
16
|
+
end
|
17
|
+
|
18
|
+
raise UnknownPrimaryKey.new(@klass) if primary_key.nil?
|
19
|
+
|
20
|
+
expects_array = ids.first.kind_of?(Array)
|
21
|
+
return ids.first if expects_array && ids.first.empty?
|
22
|
+
|
23
|
+
ids = ids.flatten.compact.uniq
|
24
|
+
|
25
|
+
case ids.size
|
26
|
+
when 0
|
27
|
+
raise ::ActiveRecord::RecordNotFound, "Couldn't find #{@klass.name} without an ID"
|
28
|
+
when 1
|
29
|
+
begin
|
30
|
+
id = decode_id(ids.first)
|
31
|
+
rescue
|
32
|
+
raise ::ActiveRecord::RecordNotFound, "Couldn't find #{@klass.name} with secret id=#{ids.first}"
|
33
|
+
end
|
34
|
+
|
35
|
+
result = find_one(id)
|
36
|
+
expects_array ? [ result ] : result
|
37
|
+
else
|
38
|
+
ids.map! do |id|
|
39
|
+
begin
|
40
|
+
decode_id(id)
|
41
|
+
rescue
|
42
|
+
raise ::ActiveRecord::RecordNotFound, "Couldn't find #{@klass.name} with secret id=#{id}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
find_some(ids)
|
47
|
+
end
|
48
|
+
rescue RangeError
|
49
|
+
raise ::ActiveRecord::RecordNotFound, "Couldn't find #{@klass.name} with an out of range ID"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
module Core
|
55
|
+
extend ActiveSupport::Concern
|
56
|
+
|
57
|
+
module ClassMethods
|
58
|
+
# Override ActiveRecord::Core#find decoding ids, if is necessary
|
59
|
+
def find(*ids)
|
11
60
|
|
12
|
-
expects_array = ids.first.kind_of?(Array)
|
13
|
-
return ids.first if expects_array && ids.first.empty?
|
14
61
|
|
15
|
-
|
62
|
+
if ids.length == 1
|
63
|
+
return super if ids.first.kind_of?(Array)
|
64
|
+
else
|
65
|
+
options = ids.slice!(ids.size - 1) if ids.last.kind_of?(Hash)
|
66
|
+
options ||= {}
|
16
67
|
|
17
|
-
|
18
|
-
|
19
|
-
raise ::ActiveRecord::RecordNotFound, "Couldn't find #{@klass.name} without an ID"
|
20
|
-
when 1
|
21
|
-
begin
|
22
|
-
id = decode_id(ids.first)
|
23
|
-
rescue
|
24
|
-
raise ::ActiveRecord::RecordNotFound, "Couldn't find #{@klass.name} with secret id=#{ids.first}"
|
68
|
+
return super ids, secret_id: false if options[:secret_id] === false
|
69
|
+
return super if ids.first.kind_of?(Array)
|
25
70
|
end
|
26
71
|
|
27
|
-
result = find_one(id)
|
28
|
-
expects_array ? [ result ] : result
|
29
|
-
else
|
30
72
|
ids.map! do |id|
|
31
73
|
begin
|
32
74
|
decode_id(id)
|
33
75
|
rescue
|
34
|
-
raise ::ActiveRecord::RecordNotFound, "Couldn't find #{
|
76
|
+
raise ::ActiveRecord::RecordNotFound, "Couldn't find #{self.name} with secret id=#{id}"
|
35
77
|
end
|
36
78
|
end
|
37
79
|
|
38
|
-
|
80
|
+
return super ids, secret_id: false
|
39
81
|
end
|
40
|
-
rescue RangeError
|
41
|
-
raise ::ActiveRecord::RecordNotFound, "Couldn't find #{@klass.name} with an out of range ID"
|
42
82
|
end
|
43
83
|
end
|
44
84
|
end
|
data/lib/secret_id/version.rb
CHANGED
data/lib/secret_id.rb
CHANGED
@@ -9,7 +9,8 @@ module SecretId
|
|
9
9
|
base.include SecretId::Base
|
10
10
|
|
11
11
|
if defined?(::ActiveRecord::Base)
|
12
|
-
|
12
|
+
base.include SecretId::ActiveRecord::Core
|
13
|
+
::ActiveRecord::Relation.include SecretId::ActiveRecord::FinderMethods
|
13
14
|
end
|
14
15
|
|
15
16
|
super
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: secret_id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastián Orellana
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description:
|
55
|
+
description: SecretId is a flexible solution for masking the identifiers of ActiveRecord.
|
56
56
|
email:
|
57
57
|
- limcross@gmail.com
|
58
58
|
executables: []
|
@@ -95,6 +95,8 @@ files:
|
|
95
95
|
- test/dummy/config/locales/en.yml
|
96
96
|
- test/dummy/config/routes.rb
|
97
97
|
- test/dummy/config/secrets.yml
|
98
|
+
- test/dummy/db/test.sqlite3
|
99
|
+
- test/dummy/log/test.log
|
98
100
|
- test/dummy/public/404.html
|
99
101
|
- test/dummy/public/422.html
|
100
102
|
- test/dummy/public/500.html
|
@@ -124,7 +126,7 @@ rubyforge_project:
|
|
124
126
|
rubygems_version: 2.4.6
|
125
127
|
signing_key:
|
126
128
|
specification_version: 4
|
127
|
-
summary:
|
129
|
+
summary: SecretId is a flexible solution for masking the identifiers of ActiveRecord.
|
128
130
|
test_files:
|
129
131
|
- test/dummy/app/assets/javascripts/application.js
|
130
132
|
- test/dummy/app/assets/stylesheets/application.css
|
@@ -154,6 +156,8 @@ test_files:
|
|
154
156
|
- test/dummy/config/routes.rb
|
155
157
|
- test/dummy/config/secrets.yml
|
156
158
|
- test/dummy/config.ru
|
159
|
+
- test/dummy/db/test.sqlite3
|
160
|
+
- test/dummy/log/test.log
|
157
161
|
- test/dummy/public/404.html
|
158
162
|
- test/dummy/public/422.html
|
159
163
|
- test/dummy/public/500.html
|