secret_id 0.0.2 → 0.1.0
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/secret_id/active_record.rb +20 -4
- data/lib/secret_id/base.rb +3 -3
- data/lib/secret_id/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61c578a2b69ba786972b304322645baa80d05c0b
|
4
|
+
data.tar.gz: 4af527cca46d9391652b84f560e31fe849380e5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81c5f65a20f1ca7c4c526d49360f500d63d9cdb89932a79c304ee77ce5c4129673ab82897e9912c6c55be8defba54aaada0f60073b4b41bb8465987d6ac81cdb
|
7
|
+
data.tar.gz: 65370b73b1fb87dc6e8d21a2c10424d5dcb85568ff885f2a617684d2c63d59914af016ea886fe0acf5c36fc222649b6232fe8bdf627d9ac27d58e0440a6e6f0a
|
@@ -5,6 +5,8 @@ module SecretId
|
|
5
5
|
included do
|
6
6
|
# Override ActiveRecord::FinderMethods#find_with_ids decoding ids
|
7
7
|
def find_with_ids(*ids)
|
8
|
+
return super(*ids) unless @klass.is_a?(SecretId)
|
9
|
+
|
8
10
|
raise UnknownPrimaryKey.new(@klass) if primary_key.nil?
|
9
11
|
|
10
12
|
expects_array = ids.first.kind_of?(Array)
|
@@ -14,15 +16,29 @@ module SecretId
|
|
14
16
|
|
15
17
|
case ids.size
|
16
18
|
when 0
|
17
|
-
raise RecordNotFound, "Couldn't find #{@klass.name} without an ID"
|
19
|
+
raise ::ActiveRecord::RecordNotFound, "Couldn't find #{@klass.name} without an ID"
|
18
20
|
when 1
|
19
|
-
|
21
|
+
begin
|
22
|
+
id = decode_id(ids.first)
|
23
|
+
rescue
|
24
|
+
raise ::ActiveRecord::RecordNotFound, "Couldn't find #{@klass.name} with secret id=#{ids.first}"
|
25
|
+
end
|
26
|
+
|
27
|
+
result = find_one(id)
|
20
28
|
expects_array ? [ result ] : result
|
21
29
|
else
|
22
|
-
|
30
|
+
ids.map! do |id|
|
31
|
+
begin
|
32
|
+
decode_id(id)
|
33
|
+
rescue
|
34
|
+
raise ::ActiveRecord::RecordNotFound, "Couldn't find #{@klass.name} with secret id=#{id}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
find_some(ids)
|
23
39
|
end
|
24
40
|
rescue RangeError
|
25
|
-
raise RecordNotFound, "Couldn't find #{@klass.name} with an out of range ID"
|
41
|
+
raise ::ActiveRecord::RecordNotFound, "Couldn't find #{@klass.name} with an out of range ID"
|
26
42
|
end
|
27
43
|
end
|
28
44
|
end
|
data/lib/secret_id/base.rb
CHANGED
@@ -5,12 +5,12 @@ module SecretId
|
|
5
5
|
included do
|
6
6
|
class_attribute :hashids
|
7
7
|
|
8
|
-
def
|
9
|
-
|
8
|
+
def to_param
|
9
|
+
secret_id
|
10
10
|
end
|
11
11
|
|
12
12
|
def secret_id
|
13
|
-
|
13
|
+
self.class.encode_id(id) unless id.nil?
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
data/lib/secret_id/version.rb
CHANGED