friendly_routes 0.4.6 → 0.5.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_routes/params/collection_params.rb +13 -6
- data/lib/friendly_routes/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe66cea5553050a8e5fd7aa79ea09a8b03ab2226
|
4
|
+
data.tar.gz: 795e61395c576e55426d68b8343ea231ac15b5c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11cd1edc4b0c4f38a00b04fc9e2a29fb403aad180e5e7a6ebe38a31d1df692ca656d7c9dab2e32c09492d4446d92bb5511d0056123b70b3b3abcd4686cbe2140
|
7
|
+
data.tar.gz: 928ba6f615b00d1fb5e8dada10c868bc95611492e6945366c0b33b48847dc3220fd7307f37b1796d10a6f33bb74d8071ec334085aceb5147349a37cc646da575
|
@@ -14,6 +14,7 @@ module FriendlyRoutes
|
|
14
14
|
@collection = collection
|
15
15
|
@key_attr = key_attr
|
16
16
|
check_params
|
17
|
+
@collection_ids = collection.pluck(:id)
|
17
18
|
end
|
18
19
|
|
19
20
|
def constraints
|
@@ -28,17 +29,23 @@ module FriendlyRoutes
|
|
28
29
|
end
|
29
30
|
|
30
31
|
# (see Base#compose)
|
31
|
-
# @param [Integer]
|
32
|
+
# @param [Integer|Object] id_or_instance collection instance or it id
|
32
33
|
# @return [String] member key attr
|
33
|
-
def compose(
|
34
|
-
|
34
|
+
def compose(id_or_instance)
|
35
|
+
instance = id_or_instance
|
36
|
+
instance = @collection.find(id_or_instance) unless instance.is_a?(ActiveRecord::Base)
|
37
|
+
instance[@key_attr]
|
35
38
|
end
|
36
39
|
|
37
40
|
# (see Base#allowed?)
|
38
|
-
# @param [Integer]
|
41
|
+
# @param [Integer|Object] id_or_instance collection instance or it id
|
39
42
|
# @return [Boolean]
|
40
|
-
def allowed?(
|
41
|
-
@collection.
|
43
|
+
def allowed?(id_or_instance)
|
44
|
+
if id_or_instance.is_a?(@collection.class)
|
45
|
+
@collection_ids.includes?(id_or_instance.id)
|
46
|
+
else
|
47
|
+
@collection.find_by(id: id_or_instance).present?
|
48
|
+
end
|
42
49
|
end
|
43
50
|
|
44
51
|
private
|