friendly_uuid 0.2.2 → 0.3.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/friendly_uuid.rb +17 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a30a5351eaad80263a47cdfe1bb76994bbb93c9e455c56a32dbafa232f71b49a
|
4
|
+
data.tar.gz: af3e8aa4a342a951e88626f2ca199f0017a63ba0a4fb9e5333d8f056720cdf9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28a9eb11b1c06bacf19406691661162d7056d9d20c318d92b5bb7becf09daf2796552070f3341d682e46accfd41bc0818a7b11374257fa61332ee8032672fcfd
|
7
|
+
data.tar.gz: 49b3acb11d0bd5209a34a163013a3083224f608164045fb1160d47bc1262d1c22f31196490858e215e8a53705e67fee2f6c56148ba4863a7cd1bd23fb9658414
|
data/lib/friendly_uuid.rb
CHANGED
@@ -20,12 +20,24 @@ module FriendlyUUID
|
|
20
20
|
end
|
21
21
|
|
22
22
|
module Class
|
23
|
-
def find(
|
24
|
-
super(self.expand(
|
23
|
+
def find(*ids)
|
24
|
+
super(self.expand(ids))
|
25
25
|
end
|
26
26
|
|
27
|
-
def expand(
|
28
|
-
|
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)
|
@@ -63,7 +75,7 @@ module FriendlyUUID
|
|
63
75
|
when "postgresql"
|
64
76
|
"LEFT(#{self.table_name}.id::text, ?) = ?"
|
65
77
|
when "sqlite3"
|
66
|
-
"SUBSTR(#{self.table_name}
|
78
|
+
"SUBSTR(#{self.table_name}.id, 0, ?) = ?"
|
67
79
|
else
|
68
80
|
raise ValueError("Unknown database type; FriendlyUUID cannot support it")
|
69
81
|
end
|