File tree Expand file tree Collapse file tree 5 files changed +14
-6
lines changed Expand file tree Collapse file tree 5 files changed +14
-6
lines changed Original file line number Diff line number Diff line change 88 - rubocop-rspec_rails
99 - rubocop-factory_bot
1010 - rubocop-obsession
11+ - rubocop-thread_safety
1112
1213AllCops :
1314 NewCops : enable
Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ group :development do
5757 gem 'rubocop-rspec_rails' , require : false
5858 gem 'rubocop-factory_bot' , require : false
5959 gem 'rubocop-obsession' , require : false
60+ gem 'rubocop-thread_safety' , require : false
6061 gem 'bundler-audit' , require : false
6162 gem 'brakeman' , require : false
6263 gem 'lefthook' , require : false
Original file line number Diff line number Diff line change 367367 rubocop-rspec (~> 3 , >= 3.0.1 )
368368 rubocop-shopify (2.15.1 )
369369 rubocop (~> 1.51 )
370+ rubocop-thread_safety (0.5.1 )
371+ rubocop (>= 0.90.0 )
370372 ruby-progressbar (1.13.0 )
371373 ruby_parser (3.21.1 )
372374 racc (~> 1.5 )
@@ -465,6 +467,7 @@ DEPENDENCIES
465467 rubocop-rspec
466468 rubocop-rspec_rails
467469 rubocop-shopify
470+ rubocop-thread_safety
468471 selenium-webdriver
469472 simplecov
470473 solid_queue
Original file line number Diff line number Diff line change @@ -5,7 +5,8 @@ module ObjectHelpers
55
66 class_methods do
77 def model
8- @model ||= name . demodulize . constantize
8+ Thread . current [ "#{ name } .model" ] ||=
9+ name . demodulize . constantize
910 end
1011
1112 def association ( association , ...)
Original file line number Diff line number Diff line change @@ -7,20 +7,22 @@ class Base < GraphQL::Schema::Object
77 include ObjectHelpers
88
99 class << self
10- def policy ( policy )
11- @ policy = policy
10+ def policy ( policy = nil )
11+ Thread . current [ " #{ name } . policy" ] || = policy
1212 end
1313
1414 def authorized? ( obj , ctx )
1515 super && pundit_authorized? ( obj , ctx )
1616 end
1717
1818 def pundit_authorized? ( obj , ctx )
19- return true unless @ policy
19+ return true unless policy
2020
2121 user = ctx [ :current_user ]
22- policy = Pundit . policy ( user , obj )
23- policy . send ( @policy )
22+
23+ Pundit
24+ . policy ( user , obj )
25+ . send ( policy )
2426 end
2527 end
2628 end
You can’t perform that action at this time.
0 commit comments