bullet_train-roles 0.1.7 → 0.1.8

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
  SHA256:
3
- metadata.gz: 95cb748cf7f1d4cb6b3ba9a28c6d7b3d7e8bab30cd1d76eb925e52ebc48741a7
4
- data.tar.gz: 8d1a5d66b9febbae5985105932f9d4f751f0e806386bb6ec9b98ff73c240e3fc
3
+ metadata.gz: 4fafcbc375644791ab3480a2bee1e43f19074e3efa30809d4770a27e80d25634
4
+ data.tar.gz: fc145307e762f0abc11839dd2710c5b11ed2747a9b514f5a32d4707268d35a21
5
5
  SHA512:
6
- metadata.gz: 9eed70dbba4e17e025885df2d7a1ce920afadfa1da90ad20194916c13d4cfeedd5f979efaf71c1609a4f9474b8b5783c31ef7477cfcd078227726a81252d8e09
7
- data.tar.gz: 43c8ed5b1db7d28f49aa171cca36eb675f95eeb37542f7dcb264691c35f55aaf2c18109b35604f8f5add5ae2142f2eba9834bddfb5e38f51aa532a79fa0d20f3
6
+ metadata.gz: cf85bf3d3df4a12751b7ac55fedf7917ec2634956e7df9c2a4d8a43e65000ff36b8740f1f0974b97e6cba4929831ef54159035a4dd4f5504fa8ef359cab95ed6
7
+ data.tar.gz: e34a82313a0291b967222780dde2e60d7ab3c14131e97270c1c1dd5c20073758e3d9347d4046c56fcc26ece2581347438e82eded64e067a19ba9fe3fdd2e42e0
data/Gemfile.lock CHANGED
@@ -9,7 +9,7 @@ GIT
9
9
  PATH
10
10
  remote: .
11
11
  specs:
12
- bullet_train-roles (0.1.7)
12
+ bullet_train-roles (0.1.8)
13
13
  active_hash
14
14
  activesupport
15
15
  cancancan
@@ -79,7 +79,7 @@ GEM
79
79
  ast (2.4.2)
80
80
  builder (3.2.4)
81
81
  byebug (11.1.3)
82
- cancancan (3.3.0)
82
+ cancancan (3.4.0)
83
83
  concurrent-ruby (1.1.9)
84
84
  crass (1.0.6)
85
85
  erubi (1.10.0)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Roles
4
- VERSION = "0.1.7"
4
+ VERSION = "0.1.8"
5
5
  end
data/lib/models/role.rb CHANGED
@@ -176,7 +176,7 @@ class Role < ActiveYaml::Base
176
176
  if @model == @parent
177
177
  return @condition = {id: @parent_ids}
178
178
  end
179
- parent_association = possible_parent_associations.find { |association| @model.method_defined?(association) || @model.method_defined?("#{association}_id") }
179
+ parent_association = possible_parent_associations.find { |association| @model.reflect_on_association(association) || @intermediary_class&.reflect_on_association(association) }
180
180
  return nil unless parent_association.present?
181
181
  # If possible, use the team_id attribute because it saves us having to join all the way back to the source parent model
182
182
  # In some scenarios this may be quicker, or if the parent model is in a different database shard, it may not even
@@ -184,7 +184,7 @@ class Role < ActiveYaml::Base
184
184
  parent_with_id = "#{parent_association}_id"
185
185
  @condition = if @model.column_names.include?(parent_with_id)
186
186
  {parent_with_id.to_sym => @parent_ids}
187
- elsif @intermediary.present? && @model.method_defined?(@intermediary) && @intermediary_class&.column_names&.include?(parent_with_id)
187
+ elsif @intermediary.present? && @model.reflect_on_association(@intermediary)
188
188
  {@intermediary.to_sym => {parent_with_id.to_sym => @parent_ids}}
189
189
  else
190
190
  {parent_association => {id: @parent_ids}}
data/lib/roles/user.rb CHANGED
@@ -9,12 +9,16 @@ module Roles
9
9
  included do
10
10
  def parent_ids_for(role, through, parent)
11
11
  parent_id_column = "#{parent}_id"
12
- # key = "#{role.key}_#{through}_#{parent_id_column}s"
12
+ key = "#{role.key}_#{through}_#{parent_id_column}s"
13
+
14
+ @_parent_ids_for_cache ||= {}
15
+ return @_parent_ids_for_cache[key] if @_parent_ids_for_cache[key]
16
+
13
17
  # TODO Maybe we should make ability caching a default feature of the gem?
14
18
  # If we do that, we would just make it check whether `ability_cache` exists.
15
19
  # return ability_cache[key] if ability_cache && ability_cache[key]
16
20
  role = nil if role.default?
17
- send(through).with_role(role).distinct.pluck(parent_id_column)
21
+ @_parent_ids_for_cache[key] = send(through).with_role(role).distinct.pluck(parent_id_column)
18
22
  # TODO Maybe we should make ability caching a default feature of the gem?
19
23
  # current_cache = ability_cache || {}
20
24
  # current_cache[key] = value
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bullet_train-roles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Prabin Poudel
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-04-19 00:00:00.000000000 Z
12
+ date: 2022-07-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: byebug
@@ -215,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
215
  - !ruby/object:Gem::Version
216
216
  version: '0'
217
217
  requirements: []
218
- rubygems_version: 3.3.0
218
+ rubygems_version: 3.2.22
219
219
  signing_key:
220
220
  specification_version: 4
221
221
  summary: Yaml-backed ApplicationHash for CanCan Roles