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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 270cb4d5ebbc534560258c054aa5a9e919dac8b0
4
- data.tar.gz: 9605c2f025439483bbf9bc12f35760f47052e7cc
3
+ metadata.gz: fe66cea5553050a8e5fd7aa79ea09a8b03ab2226
4
+ data.tar.gz: 795e61395c576e55426d68b8343ea231ac15b5c4
5
5
  SHA512:
6
- metadata.gz: 22515c1fc10f0d2ec607306ae755ed1665d8e82acd592d40351a2c9f47d997853b9c3f284c56b651d6a72f4773c6e15cae974784f2e4d9ef5071bf9bf08e26b4
7
- data.tar.gz: ba7ad4a6a9d9a8d854a83512a6f763e06c25b21594a0ca5a5da23f8c65a81c9a32fda6e60d00f1c10a2e87a16bda6688530f0e67b1ea94b4a746d7a8ff5bfe8c
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] id id of collection member
32
+ # @param [Integer|Object] id_or_instance collection instance or it id
32
33
  # @return [String] member key attr
33
- def compose(id)
34
- @collection.find(id)[@key_attr]
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] id id of collection member
41
+ # @param [Integer|Object] id_or_instance collection instance or it id
39
42
  # @return [Boolean]
40
- def allowed?(id)
41
- @collection.find_by(id: id).present?
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FriendlyRoutes
4
- VERSION = '0.4.6'
4
+ VERSION = '0.5.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friendly_routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Gritsay