secret_id 0.0.2 → 0.1.0

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: 95cd1a2112c47d113f3e34908082828922c9a4dd
4
- data.tar.gz: 125e924ad21440ab4b35bb6903e5699db73141e8
3
+ metadata.gz: 61c578a2b69ba786972b304322645baa80d05c0b
4
+ data.tar.gz: 4af527cca46d9391652b84f560e31fe849380e5f
5
5
  SHA512:
6
- metadata.gz: f429e03eafc6bf35e87a97bc7bb0e4328a3d996a1f32ce261788296504fc5d9157bc1915b2b2d481acfa65fe8d825bbe4f38dfaa3044e30b783f4a2f03f65c94
7
- data.tar.gz: 476e8cf09f5930fe156c46d5a6b454b71e6042ead75a4346f9e553b466d9f06139521c4c26ac53c9d5662bbbf8d589fa4b5df53568d8e3112ee4c21aacec3d3a
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
- result = find_one(decode_id(ids.first))
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
- find_some(ids.map {|id| decode_id(id)})
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
@@ -5,12 +5,12 @@ module SecretId
5
5
  included do
6
6
  class_attribute :hashids
7
7
 
8
- def id
9
- self.class.encode_id(read_attribute(:id)) if read_attribute(:id)
8
+ def to_param
9
+ secret_id
10
10
  end
11
11
 
12
12
  def secret_id
13
- read_attribute(:id)
13
+ self.class.encode_id(id) unless id.nil?
14
14
  end
15
15
  end
16
16
 
@@ -1,3 +1,3 @@
1
1
  module SecretId
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: secret_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastián Orellana