bullet_train-super_load_and_authorize_resource 1.5.1 → 1.5.2

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: f81cc394c759fc1978b2ebc991ceaca6aa58166547ca66fe7effa749edb9991e
4
- data.tar.gz: 97e897180acc2c38a05bc769ea797af4e7bd995625a046f15bb14959c4f4a7e9
3
+ metadata.gz: c846504e5afa68992db9ba4cf57f26c7018390faaab897ce586b4483194ffda7
4
+ data.tar.gz: '04529abe424c941fd5ce403ca31e183e36b6212ad1c9c6a80eed6fb4c33aae89'
5
5
  SHA512:
6
- metadata.gz: d4bff613bfce15a96b195c3fdb41e08ad60c9d507de2a1dba4802fe2136a155924689fde682f338b3130645387037de0b90a133563c345f13dfa0fed694a5554
7
- data.tar.gz: 6b1841e2d258ec37f0613cf4deb32a7ae5ce665ce330c2e7601ff76ea6617ca6d307af6e7460ec7aaa00ce7ceb4603aa906a03df8dbfdaf496897ce43c951623
6
+ metadata.gz: 1d29fa41b1dd5bc63d76ac7245af221ede9cee7a922d2f7be30edd59754522263eed8801c92d3a6fceee61e15ab61ecc91c0832b27e70559b1571d3187a74399
7
+ data.tar.gz: 863e9a588b817b0c8efd6c56967aa5c4741c65cbdb1755668d86752acb486e1deaee87109d8182956af610ad2b4d071027b2701064965a057ed29df71e94f20f
@@ -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.5.2"
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.5.2
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-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cancancan