pundit_can 0.1.3 → 0.1.4
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 +4 -4
- data/README.md +13 -0
- data/lib/pundit_can/load_and_authorize.rb +8 -1
- data/lib/pundit_can/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d34cbf6f7fb95547292dfbb214b16a7629178caaa493189b078d5f462beb9f19
|
|
4
|
+
data.tar.gz: 7093dfdf5fa51f7033514c3d56ad93d37a5b0085a4faa37c5d94d2e1d3ff5c81
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f8a8a1b4c3ed8d1f81a2f8245834f4bb7e86ccc6b15b34914807539585957e9e5c6d15ccfbb677b435243f554ad523cacdb4d75ff6f3528d0b9dff1efe9e5f5b
|
|
7
|
+
data.tar.gz: 10f3c693bfc592d46336d2d4ffec05c59ce89d2e32814fbb94bc4999c48554806b45e79f52a589b3f2737c8862580d1c02614d2fd28994bb629b6f58aed00d86
|
data/README.md
CHANGED
|
@@ -44,6 +44,19 @@ And it will load `@post` or `@posts` using the `PostPolicy` with the `:id` param
|
|
|
44
44
|
If there is no parent instance variable set (e.g., a non-nested route), it will fall back
|
|
45
45
|
to the default behavior of scoping with the model class.
|
|
46
46
|
|
|
47
|
+
When the association name doesn't match the model name, use the `:association` option:
|
|
48
|
+
```ruby
|
|
49
|
+
class ArticlesController < ApplicationController
|
|
50
|
+
load_resource model_class: User, parent: true
|
|
51
|
+
load_resource model_class: Article, through: :user, association: :articles
|
|
52
|
+
|
|
53
|
+
# This passes @user.articles instead of @user.posts to the ArticlePolicy::Scope
|
|
54
|
+
end
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
This is useful when you have associations like `has_many :published_posts, class_name: "Post"`
|
|
58
|
+
or other cases where the association method name differs from the model class name.
|
|
59
|
+
|
|
47
60
|
#### Customized loading
|
|
48
61
|
|
|
49
62
|
You can customize the loading for cases when the model, controller, and policies don't match up name-wise.
|
|
@@ -72,6 +72,12 @@ module PunditCan
|
|
|
72
72
|
# the scope passed to the policy will be the parent's association. For example,
|
|
73
73
|
# +through: :user+ will pass +@user.posts+ as the scope to the PostPolicy.
|
|
74
74
|
#
|
|
75
|
+
# @param [Symbol] association Optional. When used with +:through+, specifies the association
|
|
76
|
+
# method name to call on the parent. By default, the association name is derived from the
|
|
77
|
+
# model class name (e.g., +Post+ becomes +posts+). Use this option when the association name
|
|
78
|
+
# differs from the model name. For example, +through: :user, association: :articles+ will
|
|
79
|
+
# pass +@user.articles+ as the scope.
|
|
80
|
+
#
|
|
75
81
|
# @param [Constant] policy_class Optional. The policy class to use. Defaults from controller name.
|
|
76
82
|
#
|
|
77
83
|
# @param [Constant] policy_scope_class Optional. The policy scope class to use. Defaults from controller name.
|
|
@@ -102,7 +108,8 @@ module PunditCan
|
|
|
102
108
|
else
|
|
103
109
|
# When :through is specified, pass the parent's association as the scope
|
|
104
110
|
scope_class = if options[:through] && (parent = instance_variable_get("@#{options[:through]}"))
|
|
105
|
-
|
|
111
|
+
assoc = options[:association] || model_class.name.underscore.pluralize
|
|
112
|
+
parent.public_send(assoc)
|
|
106
113
|
else
|
|
107
114
|
model_class
|
|
108
115
|
end
|
data/lib/pundit_can/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pundit_can
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- candland
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-03-
|
|
11
|
+
date: 2026-03-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: pundit
|