friendly_uuid 0 → 0.3.1

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 +26 -6
  3. metadata +11 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 98e988bb5dfd439d830209d5b1faf70835abe26c7f5c0c1e5378d8951401c75f
4
- data.tar.gz: f5093ac244b08c647dcb2711f89cdf34c116176dae26914903fe1be287c6e086
3
+ metadata.gz: 758a0f77edc544b560ea4cd7488a882689c71b02e0fd07bac1d4957995ad5de3
4
+ data.tar.gz: e1cfef7017d033c98a9789b8d60b17b9fb0db6ed4b4c2f927240791b4cf2c1f7
5
5
  SHA512:
6
- metadata.gz: 294ccf76035580dcc454f3b3b5dbaf3edf3c37a1a468f7f7fed9bc08d9a65c64424f9e8a33ade79c9ef80111eb2179e94073e3117256776827eebeb228817cc3
7
- data.tar.gz: 14ed6bc1d2ab87d4df1e3428a4e89eb16fc6d8cf9660d44a5be6cdee19c5e0f9e1c3f784f79f8839e22a54b84fd6104706075cf1cf2a76ca6f6c742e80b7990a
6
+ metadata.gz: cc4de547875e962ddedf7c1ba406e7ae11d2a1a5a3b48dff1d5a64ab6f7a9e1f9fe3620ac2c291d44e1f16675a30280edce24b16dcf3df0ec4dcfed0e9580ebe
7
+ data.tar.gz: 11a12408b53044ac36f75fcdf2045004a14cec834b4375d7593ab71d70cc3d7781b324a31d55de580a4aab3484f33b49a33732a667a306a903d8fca6821813c1
data/lib/friendly_uuid.rb CHANGED
@@ -20,12 +20,24 @@ module FriendlyUUID
20
20
  end
21
21
 
22
22
  module Class
23
- def find(id)
24
- super(self.expand(id))
23
+ def find(*ids)
24
+ super(self.expand(ids))
25
25
  end
26
26
 
27
- def expand(short_uuid)
28
- self.expand_to_record(short_uuid).id
27
+ 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
40
+ end
29
41
  end
30
42
 
31
43
  def compact(uuid)
@@ -57,16 +69,24 @@ module FriendlyUUID
57
69
  end
58
70
 
59
71
  def substr_query
60
- case self.connection_config[:adapter]
72
+ case adapter
61
73
  when "mysql2"
62
74
  raise ValueError("Sorry, FriendlyUUID does not support MySQL")
63
75
  when "postgresql"
64
76
  "LEFT(#{self.table_name}.id::text, ?) = ?"
65
77
  when "sqlite3"
66
- "SUBSTR(#{self.table_name}?.id, 0, ?) = ?"
78
+ "SUBSTR(#{self.table_name}.id, 0, ?) = ?"
67
79
  else
68
80
  raise ValueError("Unknown database type; FriendlyUUID cannot support it")
69
81
  end
70
82
  end
83
+
84
+ def adapter
85
+ if respond_to?(:connection_db_config)
86
+ connection_db_config.configuration_hash[:adapter]
87
+ else
88
+ connection_config[:adapter]
89
+ end
90
+ end
71
91
  end
72
92
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friendly_uuid
3
3
  version: !ruby/object:Gem::Version
4
- version: '0'
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Carlsson
@@ -10,8 +10,16 @@ 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.
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.
15
23
  email: qhiiyr@gmail.com
16
24
  executables: []
17
25
  extensions: []