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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c9ddc6c580f50af6151214bb04a1cbf14b5816ef
4
- data.tar.gz: 6bacd091829b3210fe407658f33684b603138b01
3
+ metadata.gz: ce82368e9547cb53e9f4bc2f2d7b3f60af4ae6ac
4
+ data.tar.gz: 4fbe604cacc26c929b2401398e34ed51b240428f
5
5
  SHA512:
6
- metadata.gz: f7132b1a41aa03f331ca086765cc505970f90b39a3183eaa0a8dcb34da473a76726205feabf9222a803137cf11449a214977e2f88275eaa2610869defee86360
7
- data.tar.gz: b5e531855a91ad36d739e96325b8bb27992601e90957a8a3b1bc012858219d6e7aa3629191ef959ae20d0f17a5e9e80abe03897ea40a51147b2ce5928e766185
6
+ metadata.gz: 626905bdaa1f1b2be252efcf23babfdb0d5f85929124961e4b160b81006abf01ab695f7ca899a2be2d4090ac33bc015383a5b9b584d706b7918cbe5d36cd340c
7
+ data.tar.gz: 70916e8dfc81eb8177162591ffce3df4746c1301feef1c22f9076c514965d8b07fad2978504e9843b7542167bdfea67f5f68bb561bf71aecb0080b475bf7b415
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.gem
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
@@ -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!.new(user, record)
22
+ policy = NamespacedPolicyFinder.new(record, namespace).policy!
23
+ policy.new(user, record, namespace)
23
24
  end
24
25
  end
25
26
 
@@ -1,3 +1,3 @@
1
1
  module PunditNamespaces
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
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-18 00:00:00.000000000 Z
11
+ date: 2015-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pundit