pundit_can 0.1.0 → 0.1.1

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: e3dcf9c896cd377f57e774b151b78781f14209ce6f9654ad789186df724c6aaf
4
+ data.tar.gz: d0123ce7e4c05b6b30269b278c3603464af966b285de4ef4f03f4654edfd096f
5
5
  SHA512:
6
- metadata.gz: a96f83508916a9650fe4f14c24f0ff13d0d730cf14558e764070da4ec1eaf215c4ef1e06a91adaf09f0d013fb9e07193243a080b9bc737ea3e48dbcc866ed3c8
7
- data.tar.gz: e755108ea59470ed01e17a81a8522657b787032c8a2c7fe50459f1353389f47ba9aa2700f6517ee094788a90771e0777fe630fa3f4d5a375edd7b37af8419758
6
+ metadata.gz: 471b1dd95884dd65e71d18f8fe7e5a2284b428e298ffdbd04c0e0829305a65ecad744c44a14287d659e4550747d6479d71b2589758e8d8f341a18a0dbd0e6a98
7
+ data.tar.gz: 87f824a1f3c2c61e6f412a07ef86a4bd81f335cc8135accea067fe57864bb906e0d2059d1241cfe7958d0bf2689ed3697553b0561e4ecca0f7c9eceba4f2720d
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,14 @@ 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
+ except_actions = []
12
+ except_actions << :new if respond_to?(:new)
13
+ except_actions << :create if respond_to?(:create)
14
+
15
+ after_action :verify_policy_scoped, except: except_actions, unless: lambda {
16
+ respond_to?(:devise_controller?) && devise_controller?
17
+ }
11
18
  end
12
19
 
13
20
  class_methods do
@@ -22,9 +29,9 @@ module PunditCan
22
29
  # @param [*Symbol] actions
23
30
  #
24
31
  def skip_authorized_check *actions
25
- if actions.any?
26
- skip_after_action :verify_authorized, only: actions
27
- end
32
+ return unless actions.any?
33
+
34
+ skip_after_action :verify_authorized, only: actions
28
35
  end
29
36
 
30
37
  # skip_scoped_check
@@ -38,9 +45,9 @@ module PunditCan
38
45
  # @param [*Symbol] actions
39
46
  #
40
47
  def skip_scoped_check *actions
41
- if actions.any?
42
- skip_after_action :verify_policy_scoped, only: actions
43
- end
48
+ return unless actions.any?
49
+
50
+ skip_after_action :verify_policy_scoped, only: actions
44
51
  end
45
52
 
46
53
  # load_resource
@@ -86,16 +93,18 @@ module PunditCan
86
93
  param_key = get_param_key(options, instance_name, model_class)
87
94
 
88
95
  loaded = if options[:parent]
89
- load_parent_instance_var(model_class, param_key, options.extract!(:policy_class), options.extract!(:policy_scope_class))
96
+ load_parent_instance_var(model_class, param_key, options.extract!(:policy_class),
97
+ options.extract!(:policy_scope_class))
90
98
  else
91
- load_instance_var(model_class, param_key, options.extract!(:policy_class), options.extract!(:policy_scope_class))
99
+ load_instance_var(model_class, param_key, options.extract!(:policy_class),
100
+ options.extract!(:policy_scope_class))
92
101
  end
93
102
 
94
103
  instance_name = instance_name.pluralize unless loaded.is_a?(model_class)
95
104
  instance_variable_set("@#{instance_name}", loaded)
96
105
  end
97
106
 
98
- def get_param_key options, instance_name, model_class
107
+ def get_param_key(options, instance_name, model_class)
99
108
  if options[:parent]
100
109
  options.fetch(:param_key, :"#{instance_name || model_class&.name&.underscore}_id")
101
110
  else
@@ -105,11 +114,11 @@ module PunditCan
105
114
 
106
115
  # if a model_name option is given use that otherwise nil
107
116
  # and is parent
108
- def model_instance_name options
117
+ def model_instance_name(options)
109
118
  options[:model_class].name.underscore if options[:model_class].present? && options[:parent]
110
119
  end
111
120
 
112
- def load_instance_var model_class, param_key, policy_kwopts, policy_scope_kwopts
121
+ def load_instance_var(model_class, param_key, policy_kwopts, policy_scope_kwopts)
113
122
  case params[:action]
114
123
  when "index"
115
124
  load_scope(model_class, policy_kwopts, policy_scope_kwopts)
@@ -128,17 +137,17 @@ module PunditCan
128
137
  end
129
138
  end
130
139
 
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
140
+ def load_parent_instance_var(model_class, param_key, policy_kwopts, policy_scope_kwopts)
141
+ return unless params[param_key]
142
+
143
+ load_model(model_class, param_key, policy_kwopts, policy_scope_kwopts, :show?)
135
144
  end
136
145
 
137
- def load_model model_class, param_key, policy_kwopts, policy_scope_kwopts, query = nil
146
+ def load_model(model_class, param_key, policy_kwopts, policy_scope_kwopts, query = nil)
138
147
  authorize(policy_scope(model_class, **policy_scope_kwopts).find(params[param_key]), query, **policy_kwopts)
139
148
  end
140
149
 
141
- def load_scope model_class, policy_kwopts, policy_scope_kwopts
150
+ def load_scope(model_class, policy_kwopts, policy_scope_kwopts)
142
151
  authorize(policy_scope(model_class, **policy_scope_kwopts), **policy_kwopts)
143
152
  end
144
153
  end
@@ -1,3 +1,3 @@
1
1
  module PunditCan
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
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.1
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.