pundit_namespaces 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +37 -0
- data/lib/pundit_namespaces.rb +5 -4
- data/lib/pundit_namespaces/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce82368e9547cb53e9f4bc2f2d7b3f60af4ae6ac
|
4
|
+
data.tar.gz: 4fbe604cacc26c929b2401398e34ed51b240428f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 626905bdaa1f1b2be252efcf23babfdb0d5f85929124961e4b160b81006abf01ab695f7ca899a2be2d4090ac33bc015383a5b9b584d706b7918cbe5d36cd340c
|
7
|
+
data.tar.gz: 70916e8dfc81eb8177162591ffce3df4746c1301feef1c22f9076c514965d8b07fad2978504e9843b7542167bdfea67f5f68bb561bf71aecb0080b475bf7b415
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -29,6 +29,43 @@ class ApplicationController < ActionController::Base
|
|
29
29
|
end
|
30
30
|
```
|
31
31
|
|
32
|
+
The base policy (usually `ApplicationPolicy`) needs to have a third parameter
|
33
|
+
called `namespace` holding the namespace used to search for other policies.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
class ApplicationPolicy
|
37
|
+
attr_reader :user, :record, :namespace
|
38
|
+
|
39
|
+
def initialize(user, record, namespace = nil)
|
40
|
+
@user = user
|
41
|
+
@record = record
|
42
|
+
@namespace = namespace
|
43
|
+
end
|
44
|
+
|
45
|
+
def show?
|
46
|
+
scope.where(:id => record.id).exists?
|
47
|
+
end
|
48
|
+
|
49
|
+
def scope
|
50
|
+
PunditNamespaces.policy_scope!(user, record.class, namespace)
|
51
|
+
end
|
52
|
+
|
53
|
+
class Scope
|
54
|
+
attr_reader :user, :scope, :namespace
|
55
|
+
|
56
|
+
def initialize(user, scope, namespace = nil)
|
57
|
+
@user = user
|
58
|
+
@scope = scope
|
59
|
+
@namespace = namespace
|
60
|
+
end
|
61
|
+
|
62
|
+
def resolve
|
63
|
+
scope.none
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
32
69
|
## Usage
|
33
70
|
|
34
71
|
As described in the installation part, the `pundit_namespace` method has to
|
data/lib/pundit_namespaces.rb
CHANGED
@@ -5,21 +5,22 @@ module PunditNamespaces
|
|
5
5
|
class <<self
|
6
6
|
def policy_scope(user, scope, namespace = nil)
|
7
7
|
policy_scope = NamespacedPolicyFinder.new(scope, namespace).scope
|
8
|
-
policy_scope.new(user, scope).resolve if policy_scope
|
8
|
+
policy_scope.new(user, scope, namespace).resolve if policy_scope
|
9
9
|
end
|
10
10
|
|
11
11
|
def policy_scope!(user, scope, namespace = nil)
|
12
12
|
policy_scope = NamespacedPolicyFinder.new(scope, namespace).scope!
|
13
|
-
policy_scope.new(user, scope).resolve
|
13
|
+
policy_scope.new(user, scope, namespace).resolve
|
14
14
|
end
|
15
15
|
|
16
16
|
def policy(user, record, namespace = nil)
|
17
17
|
policy = NamespacedPolicyFinder.new(record, namespace).policy
|
18
|
-
policy.new(user, record) if policy
|
18
|
+
policy.new(user, record, namespace) if policy
|
19
19
|
end
|
20
20
|
|
21
21
|
def policy!(user, record, namespace = nil)
|
22
|
-
NamespacedPolicyFinder.new(record, namespace).policy
|
22
|
+
policy = NamespacedPolicyFinder.new(record, namespace).policy!
|
23
|
+
policy.new(user, record, namespace)
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pundit_namespaces
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Spieker
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pundit
|