pundit_can 0.1.0 → 0.1.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: 6a70b76f365ad9d949e7db20d9fd1eebc689915d18c835801fb2078d98628b3b
4
- data.tar.gz: b30f0f0ce6095d46818f7d47bbe3f95b8e7df58664929d0aa1e1e4a93122ab7e
3
+ metadata.gz: 0e76045d5b38c684890accf17f380b37855a6a27ed83d379552893c1c3a2bd41
4
+ data.tar.gz: 5f3c777c019c7fc6e8a6a21de41f65b76f3c3c94607dbe701ecab06bb1a0bd63
5
5
  SHA512:
6
- metadata.gz: a96f83508916a9650fe4f14c24f0ff13d0d730cf14558e764070da4ec1eaf215c4ef1e06a91adaf09f0d013fb9e07193243a080b9bc737ea3e48dbcc866ed3c8
7
- data.tar.gz: e755108ea59470ed01e17a81a8522657b787032c8a2c7fe50459f1353389f47ba9aa2700f6517ee094788a90771e0777fe630fa3f4d5a375edd7b37af8419758
6
+ metadata.gz: de3b0f7d4b32707547cd68afe69abbda6d88240a29ea29f5f1a1337606b088f18e6165844a100b681f59b687257150c53f32f23fd38ac579ee7f8fb0a851652e
7
+ data.tar.gz: f6b6e599bb905ff5c34ccdd6fae902b436facb1cbf4a4dd67a1cfc0cd03d07c85d557303660dd6920ea3f0c8e980a629d865fbb38758c0bc05e6e69ec5917fbd
data/Rakefile CHANGED
@@ -1,3 +1,13 @@
1
1
  require "bundler/setup"
2
2
 
3
3
  require "bundler/gem_tasks"
4
+
5
+ require "rake/testtask"
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.test_files = FileList["test/*_test.rb"] + FileList["test/pundit_can/*_test.rb"]
9
+ t.libs << "test"
10
+ end
11
+
12
+ desc "Run tests"
13
+ task default: :test
@@ -7,7 +7,12 @@ module PunditCan
7
7
 
8
8
  included do
9
9
  after_action :verify_authorized, unless: -> { respond_to?(:devise_controller?) && devise_controller? }
10
- after_action :verify_policy_scoped, except: [:new, :create], unless: -> { respond_to?(:devise_controller?) && devise_controller? }
10
+
11
+ after_action :verify_policy_scoped,
12
+ unless: lambda {
13
+ %i[new create].include?(action_name.to_sym) ||
14
+ (respond_to?(:devise_controller?) && devise_controller?)
15
+ }
11
16
  end
12
17
 
13
18
  class_methods do
@@ -22,9 +27,9 @@ module PunditCan
22
27
  # @param [*Symbol] actions
23
28
  #
24
29
  def skip_authorized_check *actions
25
- if actions.any?
26
- skip_after_action :verify_authorized, only: actions
27
- end
30
+ return unless actions.any?
31
+
32
+ skip_after_action :verify_authorized, only: actions
28
33
  end
29
34
 
30
35
  # skip_scoped_check
@@ -38,9 +43,9 @@ module PunditCan
38
43
  # @param [*Symbol] actions
39
44
  #
40
45
  def skip_scoped_check *actions
41
- if actions.any?
42
- skip_after_action :verify_policy_scoped, only: actions
43
- end
46
+ return unless actions.any?
47
+
48
+ skip_after_action :verify_policy_scoped, only: actions
44
49
  end
45
50
 
46
51
  # load_resource
@@ -86,16 +91,18 @@ module PunditCan
86
91
  param_key = get_param_key(options, instance_name, model_class)
87
92
 
88
93
  loaded = if options[:parent]
89
- load_parent_instance_var(model_class, param_key, options.extract!(:policy_class), options.extract!(:policy_scope_class))
94
+ load_parent_instance_var(model_class, param_key, options.extract!(:policy_class),
95
+ options.extract!(:policy_scope_class))
90
96
  else
91
- load_instance_var(model_class, param_key, options.extract!(:policy_class), options.extract!(:policy_scope_class))
97
+ load_instance_var(model_class, param_key, options.extract!(:policy_class),
98
+ options.extract!(:policy_scope_class))
92
99
  end
93
100
 
94
101
  instance_name = instance_name.pluralize unless loaded.is_a?(model_class)
95
102
  instance_variable_set("@#{instance_name}", loaded)
96
103
  end
97
104
 
98
- def get_param_key options, instance_name, model_class
105
+ def get_param_key(options, instance_name, model_class)
99
106
  if options[:parent]
100
107
  options.fetch(:param_key, :"#{instance_name || model_class&.name&.underscore}_id")
101
108
  else
@@ -105,11 +112,11 @@ module PunditCan
105
112
 
106
113
  # if a model_name option is given use that otherwise nil
107
114
  # and is parent
108
- def model_instance_name options
115
+ def model_instance_name(options)
109
116
  options[:model_class].name.underscore if options[:model_class].present? && options[:parent]
110
117
  end
111
118
 
112
- def load_instance_var model_class, param_key, policy_kwopts, policy_scope_kwopts
119
+ def load_instance_var(model_class, param_key, policy_kwopts, policy_scope_kwopts)
113
120
  case params[:action]
114
121
  when "index"
115
122
  load_scope(model_class, policy_kwopts, policy_scope_kwopts)
@@ -128,17 +135,17 @@ module PunditCan
128
135
  end
129
136
  end
130
137
 
131
- def load_parent_instance_var model_class, param_key, policy_kwopts, policy_scope_kwopts
132
- if params[param_key]
133
- load_model(model_class, param_key, policy_kwopts, policy_scope_kwopts, :show?)
134
- end
138
+ def load_parent_instance_var(model_class, param_key, policy_kwopts, policy_scope_kwopts)
139
+ return unless params[param_key]
140
+
141
+ load_model(model_class, param_key, policy_kwopts, policy_scope_kwopts, :show?)
135
142
  end
136
143
 
137
- def load_model model_class, param_key, policy_kwopts, policy_scope_kwopts, query = nil
144
+ def load_model(model_class, param_key, policy_kwopts, policy_scope_kwopts, query = nil)
138
145
  authorize(policy_scope(model_class, **policy_scope_kwopts).find(params[param_key]), query, **policy_kwopts)
139
146
  end
140
147
 
141
- def load_scope model_class, policy_kwopts, policy_scope_kwopts
148
+ def load_scope(model_class, policy_kwopts, policy_scope_kwopts)
142
149
  authorize(policy_scope(model_class, **policy_scope_kwopts), **policy_kwopts)
143
150
  end
144
151
  end
@@ -1,3 +1,3 @@
1
1
  module PunditCan
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pundit_can
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - candland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-09 00:00:00.000000000 Z
11
+ date: 2023-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: pundit
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 7.0.4.2
19
+ version: 2.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 7.0.4.2
26
+ version: 2.0.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: pundit
28
+ name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 2.0.0
33
+ version: 7.0.4.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 2.0.0
40
+ version: 7.0.4.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rails-controller-testing
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  - !ruby/object:Gem::Version
90
90
  version: '0'
91
91
  requirements: []
92
- rubygems_version: 3.3.7
92
+ rubygems_version: 3.3.26
93
93
  signing_key:
94
94
  specification_version: 4
95
95
  summary: Add cancan like load and authorize to controllers.