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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 340bc87e37b86b2aea59c99812302fa2e616af91
4
- data.tar.gz: 79f3d9754889cfdd68b6abd182758a1546634238
3
+ metadata.gz: 1db5271d1f61522d4edfc7709a139fe0079e531e
4
+ data.tar.gz: 15b0b99878f3b3d9160dee62be09868bfbfb304f
5
5
  SHA512:
6
- metadata.gz: e589da8632dad772df73e3418e4f0f1523127c3b9dd3c3e31bff25373ffdf1fec361647d16380fc76033bbbc07a6931129b53b7fa37f4425041e2d93c900cc1a
7
- data.tar.gz: 6c0ef3c7cb6f5288d3ef617428722930dae635db8f79de522c23f0bdccda240f940bf42d5ddb31f279fe5545043b0d7101e43accd73a168e03fb8d4ea78b54f6
6
+ metadata.gz: a592288a7a03b00725f4da5a32a73235f18aa418283e731c7f12fb93462860e188096e5f61b6fde98afd2539b2b0fb55856b9799d4f86ffa45c8afec44f62ed1
7
+ data.tar.gz: a0713629734c444abec72b2c39af8865797213192725ebbbfa65a12d159a792e3891f661cd1d1781c3f8b67d875f35c3cb526c65794a755c1c06de1477baf8b9
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # PunditExtra
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/pundit_extra.svg)](http://badge.fury.io/rb/pundit_extra)
4
- [![Build Status](https://travis-ci.org/DannyBen/pundit_extra.svg?branch=master)](https://travis-ci.org/DannyBen/pundit_extra)
5
- [![Code Climate](https://codeclimate.com/github/DannyBen/pundit_extra/badges/gpa.svg)](https://codeclimate.com/github/DannyBen/pundit_extra)
6
- [![Dependency Status](https://gemnasium.com/DannyBen/pundit_extra.svg)](https://gemnasium.com/DannyBen/pundit_extra)
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 onm the current action.
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
- elsif ['new', 'create'].include? action
36
+
37
+ elsif action == 'new'
38
+ resource = scope.new
39
+
40
+ elsif action == 'create'
36
41
  resource = scope.new
37
- resource.attributes = send("#{resource_name}_params") if action == 'create'
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
@@ -1,3 +1,3 @@
1
1
  module PunditExtra
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
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.2.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-05-24 00:00:00.000000000 Z
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.4.6
87
+ rubygems_version: 2.6.6
88
88
  signing_key:
89
89
  specification_version: 4
90
90
  summary: Additions for Pundit