friendly_uuid 0.3.1 → 0.3.2

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/friendly_uuid.rb +13 -17
  3. metadata +9 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 758a0f77edc544b560ea4cd7488a882689c71b02e0fd07bac1d4957995ad5de3
4
- data.tar.gz: e1cfef7017d033c98a9789b8d60b17b9fb0db6ed4b4c2f927240791b4cf2c1f7
3
+ metadata.gz: cf8d5e72bcdfc392496d82ff2edb0f3bb16f5fbb390c4bfeee593e4a4f1d809a
4
+ data.tar.gz: ac2ca5df9575b956d6057faac4b061e9f4d5cbfc1bf8b678cc6f1f9249d949e2
5
5
  SHA512:
6
- metadata.gz: cc4de547875e962ddedf7c1ba406e7ae11d2a1a5a3b48dff1d5a64ab6f7a9e1f9fe3620ac2c291d44e1f16675a30280edce24b16dcf3df0ec4dcfed0e9580ebe
7
- data.tar.gz: 11a12408b53044ac36f75fcdf2045004a14cec834b4375d7593ab71d70cc3d7781b324a31d55de580a4aab3484f33b49a33732a667a306a903d8fca6821813c1
6
+ metadata.gz: 3c030af33c0bad3efe7e7eba15b8ab9146883c4ce3bb1c2cdbe3a53964b34306d54c83749fc3ac814b04d08aaf8299dcc221ef4676bc2a838a9a8b4d55b897f1
7
+ data.tar.gz: 9772457ed4a6441ec49db31e42529fd400c33fb6caab0d73d5193c23c48477e858b14eaa63467b40e6b7ad466153d21e70a15b7322458bf915a5ca317a87ef3f
data/lib/friendly_uuid.rb CHANGED
@@ -21,22 +21,21 @@ module FriendlyUUID
21
21
 
22
22
  module Class
23
23
  def find(*ids)
24
- super(self.expand(ids))
24
+ ids = self.expand(ids) if ids.flatten.any? { |id| id.present? }
25
+
26
+ super(ids)
25
27
  end
26
28
 
27
29
  def expand(short_uuids)
28
- # If a single ID passed as a string
29
- return self.expand_to_record(short_uuids).id if short_uuids.class == String
30
-
31
- # If a single ID passed as a non-nested array
32
- if short_uuids[0].class != Array && short_uuids.length == 1
33
- return self.expand_to_record(short_uuids.join).id
34
- end
35
-
36
- short_uuids.flatten!
37
-
38
- short_uuids.map do |uuid|
39
- self.expand_to_record(uuid).id
30
+ if short_uuids.is_a?(String)
31
+ self.expand_to_record(short_uuids)&.id
32
+ elsif short_uuids[0].is_a?(String) && short_uuids.length == 1
33
+ self.expand_to_record(short_uuids.join)&.id
34
+ elsif short_uuids.is_a?(Array)
35
+ short_uuids.flatten!
36
+ short_uuids.map do |uuid|
37
+ self.expand_to_record(uuid.to_s)&.id
38
+ end
40
39
  end
41
40
  end
42
41
 
@@ -49,10 +48,7 @@ module FriendlyUUID
49
48
  end
50
49
 
51
50
  def expand_to_record(short_uuid)
52
- raise ActiveRecord::RecordNotFound unless short_uuid
53
- record = self.possible_expansions(short_uuid).first
54
- raise ActiveRecord::RecordNotFound unless record
55
- record
51
+ self.possible_expansions(short_uuid).first
56
52
  end
57
53
 
58
54
  def possible_expansions(short_uuid)
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friendly_uuid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Carlsson
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2020-10-11 00:00:00.000000000 Z
@@ -20,7 +20,7 @@ description: |2
20
20
  FriendlyUUID URLs are exactly as unique as they need to be. The first record will be one character. Would-be collisions expand to two characters, and so on.
21
21
 
22
22
  FriendlyUUID is inspired by friendly_id, but is focused on being lightweight and specific to models with UUID primary keys.
23
- email: qhiiyr@gmail.com
23
+ email: ben@twos.dev
24
24
  executables: []
25
25
  extensions: []
26
26
  extra_rdoc_files: []
@@ -28,17 +28,18 @@ files:
28
28
  - lib/friendly_uuid.rb
29
29
  homepage: https://github.com/glacials/friendly_uuid
30
30
  licenses:
31
- - MIT
31
+ - CC-BY-NC-SA-4.0
32
+ - LicenseRef-Licenseland
32
33
  metadata: {}
33
- post_install_message:
34
+ post_install_message:
34
35
  rdoc_options: []
35
36
  require_paths:
36
37
  - lib
37
38
  required_ruby_version: !ruby/object:Gem::Requirement
38
39
  requirements:
39
- - - ">="
40
+ - - '='
40
41
  - !ruby/object:Gem::Version
41
- version: '0'
42
+ version: 2.7.2
42
43
  required_rubygems_version: !ruby/object:Gem::Requirement
43
44
  requirements:
44
45
  - - ">="
@@ -46,7 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
47
  version: '0'
47
48
  requirements: []
48
49
  rubygems_version: 3.1.4
49
- signing_key:
50
+ signing_key:
50
51
  specification_version: 4
51
52
  summary: Make UUIDs pretty enough for use in URLs
52
53
  test_files: []