friendly_uuid 0.3.0 → 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 +22 -18
  3. metadata +19 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a30a5351eaad80263a47cdfe1bb76994bbb93c9e455c56a32dbafa232f71b49a
4
- data.tar.gz: af3e8aa4a342a951e88626f2ca199f0017a63ba0a4fb9e5333d8f056720cdf9a
3
+ metadata.gz: cf8d5e72bcdfc392496d82ff2edb0f3bb16f5fbb390c4bfeee593e4a4f1d809a
4
+ data.tar.gz: ac2ca5df9575b956d6057faac4b061e9f4d5cbfc1bf8b678cc6f1f9249d949e2
5
5
  SHA512:
6
- metadata.gz: 28a9eb11b1c06bacf19406691661162d7056d9d20c318d92b5bb7becf09daf2796552070f3341d682e46accfd41bc0818a7b11374257fa61332ee8032672fcfd
7
- data.tar.gz: 49b3acb11d0bd5209a34a163013a3083224f608164045fb1160d47bc1262d1c22f31196490858e215e8a53705e67fee2f6c56148ba4863a7cd1bd23fb9658414
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)
@@ -69,7 +65,7 @@ module FriendlyUUID
69
65
  end
70
66
 
71
67
  def substr_query
72
- case self.connection_config[:adapter]
68
+ case adapter
73
69
  when "mysql2"
74
70
  raise ValueError("Sorry, FriendlyUUID does not support MySQL")
75
71
  when "postgresql"
@@ -80,5 +76,13 @@ module FriendlyUUID
80
76
  raise ValueError("Unknown database type; FriendlyUUID cannot support it")
81
77
  end
82
78
  end
79
+
80
+ def adapter
81
+ if respond_to?(:connection_db_config)
82
+ connection_db_config.configuration_hash[:adapter]
83
+ else
84
+ connection_config[:adapter]
85
+ end
86
+ end
83
87
  end
84
88
  end
metadata CHANGED
@@ -1,18 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friendly_uuid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
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
12
12
  dependencies: []
13
- description: FriendlyUUID shortens every UUID to have only as many characters as it
14
- needs to be unique.
15
- email: qhiiyr@gmail.com
13
+ description: |2
14
+ FriendlyUUID is a Rails gem that shortens your UUID records' URLs.
15
+
16
+ What once was 758d633c-61d4-4dfc-ba52-b7b498971097 becomes 758d.
17
+
18
+ FriendlyUUID does not introduce any new state to your models, even under the hood.
19
+
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
+
22
+ FriendlyUUID is inspired by friendly_id, but is focused on being lightweight and specific to models with UUID primary keys.
23
+ email: ben@twos.dev
16
24
  executables: []
17
25
  extensions: []
18
26
  extra_rdoc_files: []
@@ -20,17 +28,18 @@ files:
20
28
  - lib/friendly_uuid.rb
21
29
  homepage: https://github.com/glacials/friendly_uuid
22
30
  licenses:
23
- - MIT
31
+ - CC-BY-NC-SA-4.0
32
+ - LicenseRef-Licenseland
24
33
  metadata: {}
25
- post_install_message:
34
+ post_install_message:
26
35
  rdoc_options: []
27
36
  require_paths:
28
37
  - lib
29
38
  required_ruby_version: !ruby/object:Gem::Requirement
30
39
  requirements:
31
- - - ">="
40
+ - - '='
32
41
  - !ruby/object:Gem::Version
33
- version: '0'
42
+ version: 2.7.2
34
43
  required_rubygems_version: !ruby/object:Gem::Requirement
35
44
  requirements:
36
45
  - - ">="
@@ -38,7 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
38
47
  version: '0'
39
48
  requirements: []
40
49
  rubygems_version: 3.1.4
41
- signing_key:
50
+ signing_key:
42
51
  specification_version: 4
43
52
  summary: Make UUIDs pretty enough for use in URLs
44
53
  test_files: []