pundit_extra 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/lib/pundit_extra/resource_autoload.rb +24 -2
- data/lib/pundit_extra/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1db5271d1f61522d4edfc7709a139fe0079e531e
|
4
|
+
data.tar.gz: 15b0b99878f3b3d9160dee62be09868bfbfb304f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a592288a7a03b00725f4da5a32a73235f18aa418283e731c7f12fb93462860e188096e5f61b6fde98afd2539b2b0fb55856b9799d4f86ffa45c8afec44f62ed1
|
7
|
+
data.tar.gz: a0713629734c444abec72b2c39af8865797213192725ebbbfa65a12d159a792e3891f661cd1d1781c3f8b67d875f35c3cb526c65794a755c1c06de1477baf8b9
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# PunditExtra
|
2
2
|
|
3
|
-
[![Gem
|
4
|
-
[![
|
5
|
-
[![Code Climate](https://
|
6
|
-
[![
|
3
|
+
[![Gem](https://img.shields.io/gem/v/pundit_extra.svg?style=flat-square)](https://rubygems.org/gems/pundit_extra)
|
4
|
+
[![Travis](https://img.shields.io/travis/DannyBen/pundit_extra.svg?style=flat-square)](https://travis-ci.org/DannyBen/pundit_extra)
|
5
|
+
[![Code Climate](https://img.shields.io/codeclimate/github/DannyBen/pundit_extra.svg?style=flat-square)](https://codeclimate.com/github/DannyBen/pundit_extra)
|
6
|
+
[![Gemnasium](https://img.shields.io/gemnasium/DannyBen/pundit_extra.svg?style=flat-square)](https://gemnasium.com/DannyBen/pundit_extra)
|
7
7
|
|
8
8
|
This library borrows functionality from [CanCan(Can)][2] and adds it to [Pundit][1].
|
9
9
|
|
@@ -62,7 +62,7 @@ end
|
|
62
62
|
```
|
63
63
|
|
64
64
|
The `load_resource` filter will create the appropriate instance variable
|
65
|
-
based
|
65
|
+
based on the current action.
|
66
66
|
|
67
67
|
The `authorize_resource` filter will call Pundit's `authorize @model` in each
|
68
68
|
action.
|
@@ -29,17 +29,25 @@ module PunditExtra
|
|
29
29
|
scope = resource_class
|
30
30
|
action = params[:action]
|
31
31
|
varname = resource_name
|
32
|
+
|
32
33
|
if action == 'index'
|
33
34
|
varname = controller_name
|
34
35
|
resource = policy_scope resource_class
|
35
|
-
|
36
|
+
|
37
|
+
elsif action == 'new'
|
38
|
+
resource = scope.new
|
39
|
+
|
40
|
+
elsif action == 'create'
|
36
41
|
resource = scope.new
|
37
|
-
resource.attributes =
|
42
|
+
resource.attributes = resource_attributes resource, action
|
43
|
+
|
38
44
|
elsif params[:id]
|
39
45
|
resource = scope.find params[:id]
|
46
|
+
|
40
47
|
else
|
41
48
|
resource = nil
|
42
49
|
end
|
50
|
+
|
43
51
|
instance_variable_set "@#{varname}", resource
|
44
52
|
end
|
45
53
|
|
@@ -65,5 +73,19 @@ module PunditExtra
|
|
65
73
|
def resource_instance
|
66
74
|
instance_variable_get "@#{resource_name}"
|
67
75
|
end
|
76
|
+
|
77
|
+
def resource_attributes(resource, action)
|
78
|
+
if has_permitted_attributes? resource, action
|
79
|
+
permitted_attributes(resource)
|
80
|
+
else
|
81
|
+
send "#{resource_name}_params"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def has_permitted_attributes?(resource, action)
|
86
|
+
return true if policy(resource).respond_to? "permitted_attributes_for_#{action}"
|
87
|
+
return true if policy(resource).respond_to? :permitted_attributes
|
88
|
+
false
|
89
|
+
end
|
68
90
|
end
|
69
91
|
end
|
data/lib/pundit_extra/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pundit_extra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: combustion
|
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
86
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.
|
87
|
+
rubygems_version: 2.6.6
|
88
88
|
signing_key:
|
89
89
|
specification_version: 4
|
90
90
|
summary: Additions for Pundit
|