bullet_train-super_load_and_authorize_resource 1.5.1 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f81cc394c759fc1978b2ebc991ceaca6aa58166547ca66fe7effa749edb9991e
4
- data.tar.gz: 97e897180acc2c38a05bc769ea797af4e7bd995625a046f15bb14959c4f4a7e9
3
+ metadata.gz: 55b8c178e08ec31fa070c7050997504e62ad3fe5a3144ab48aaabc22a024bbb6
4
+ data.tar.gz: b26bec97cc2bdfd035ad54556ad86fb5dc11e09fd9703065cdc849376b29980d
5
5
  SHA512:
6
- metadata.gz: d4bff613bfce15a96b195c3fdb41e08ad60c9d507de2a1dba4802fe2136a155924689fde682f338b3130645387037de0b90a133563c345f13dfa0fed694a5554
7
- data.tar.gz: 6b1841e2d258ec37f0613cf4deb32a7ae5ce665ce330c2e7601ff76ea6617ca6d307af6e7460ec7aaa00ce7ceb4603aa906a03df8dbfdaf496897ce43c951623
6
+ metadata.gz: 20eaceb1d47a3f75a9c38902ba57977c7ea346eecfb6299f3a8394da440f353ed7eea32cee600c8c97d8c3d896a5ed0e09c9de188a16e220088b7fba1eded562
7
+ data.tar.gz: 76361205a48f962b66066a531452509b562979c8f1043c37d2c9e7a42d0a5fce085a31c95f4fc66b5f9116fda9b1c8d2b53d70b3767ec9746c258c4e54c9ae8a
@@ -2,17 +2,18 @@ module BulletTrain::LoadsAndAuthorizesResource
2
2
  extend ActiveSupport::Concern
3
3
 
4
4
  class_methods do
5
+ # Returns an array of module names based on the classes namespace minus regex_to_remove_controller_namespace
5
6
  def model_namespace_from_controller_namespace
6
- controller_class_name =
7
- if regex_to_remove_controller_namespace
8
- name.gsub(regex_to_remove_controller_namespace, "")
9
- else
10
- name
11
- end
12
- namespace = controller_class_name.split("::")
13
- # Remove "::ThingsController"
14
- namespace.pop
15
- namespace
7
+ name
8
+ .gsub(regex_to_remove_controller_namespace || //, "")
9
+ .split("::")
10
+ .tap(&:pop) # drops actual class name
11
+ end
12
+
13
+ def regex_to_remove_controller_namespace
14
+ return super if defined?(super)
15
+
16
+ raise "This is a template method that needs to be implemented by controllers including LoadsAndAuthorizesResource."
16
17
  end
17
18
 
18
19
  # this is one of the few pieces of 'magical' functionality that bullet train implements
@@ -202,22 +203,14 @@ module BulletTrain::LoadsAndAuthorizesResource
202
203
  end
203
204
  end
204
205
 
205
- def regex_to_remove_controller_namespace
206
- raise "This is a template method that needs to be implemented by controllers including LoadsAndAuthorizesResource."
207
- end
208
-
209
206
  def load_team
210
- # Not all objects that need to be authorized belong to a team,
211
- # so we give @team a nil value if no association is found.
212
- begin
213
- # Sometimes `@team` has already been populated by earlier `before_action` steps.
214
- @team ||= @child_object&.team || @parent_object&.team
215
- rescue NoMethodError
216
- @team = nil
217
- end
207
+ @team ||= @child_object&.try(:team) || @parent_object&.try(:team)
218
208
 
219
- # Update current attributes.
220
- Current.team = @team
209
+ return unless @team
210
+
211
+ if defined?(Current) && Current.respond_to?(:team=)
212
+ Current.team = @team
213
+ end
221
214
 
222
215
  # If the currently loaded team is saved to the database, make that the user's new current team.
223
216
  if @team.try(:persisted?)
@@ -1,5 +1,5 @@
1
1
  module BulletTrain
2
2
  module SuperLoadAndAuthorizeResource
3
- VERSION = "1.5.1"
3
+ VERSION = "1.6.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bullet_train-super_load_and_authorize_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Culver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-02 00:00:00.000000000 Z
11
+ date: 2023-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cancancan