bullet_train-super_load_and_authorize_resource 1.5.0 → 1.5.2

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: 702f2673697dd7300a0990ca65e7470ab9866112771631c7fc0a8785f9203237
4
- data.tar.gz: e64370f49da75f0b2710deba4f9836edca02ab097218913eb47c84f9979395ca
3
+ metadata.gz: c846504e5afa68992db9ba4cf57f26c7018390faaab897ce586b4483194ffda7
4
+ data.tar.gz: '04529abe424c941fd5ce403ca31e183e36b6212ad1c9c6a80eed6fb4c33aae89'
5
5
  SHA512:
6
- metadata.gz: cc2a12ccc8c79f87c8045a712e299632caefdd48cc06d509a9fd715b687706f79eebfaac9c38f4a89935e5d25e5bd397b6e5f7930f42bbd6ab33a1e65a9dbb4e
7
- data.tar.gz: 40a5277bc7dd4ad9ec87d4c965a58012e2f984461775465a5c77cf14c8250dfd4315091f0354c493c885c438b13cc88dbe15e9c1e858b043c187bd3951723a53
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.0"
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.0
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