banken 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +12 -2
- data/lib/banken.rb +10 -4
- data/lib/banken/loyalty_finder.rb +5 -6
- data/lib/banken/version.rb +1 -1
- data/lib/generators/banken/loyalty/templates/loyalty.rb +0 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4faea250e6de5c7022b73be747b18978e4569a1e
|
4
|
+
data.tar.gz: fe8b0f64b93b370f9beaa04ea581180a4d2b3760
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49a1116ac331febca898385de35fcd0c518840cb3eab76cca7e266c99832f19572063573d8f6d3b9f18c97271885091d636594429d1ffbcbb22d44c82cfb1ae7
|
7
|
+
data.tar.gz: 711723dd4d3c2118624d7dca4bcaaeddef0bf203c30c063d18833df70644495634984da76196bddd6c68b685c5f7e3a232e55c808c0e5f9c672e9e6414fa6c64
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
<img width="350"src="https://raw.github.com/wiki/kyuden/banken/images/banken.png">
|
1
|
+
<img width="350" src="https://raw.github.com/wiki/kyuden/banken/images/banken.png">
|
2
2
|
|
3
3
|
[![Build Status](https://img.shields.io/travis/kyuden/banken/master.svg)](https://travis-ci.org/kyuden/banken)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/kyuden/banken/badges/gpa.svg)](https://codeclimate.com/github/kyuden/banken)
|
@@ -157,6 +157,16 @@ conditionally showing links or buttons in the view:
|
|
157
157
|
<% end %>
|
158
158
|
```
|
159
159
|
|
160
|
+
If you are using namespace in your controller and policy,
|
161
|
+
you can access the policy passing string like 'admin/posts' as a second argument.
|
162
|
+
Below calls Admin::PostsLoyalty.
|
163
|
+
|
164
|
+
``` erb
|
165
|
+
<% if loyalty(@post, 'admin/posts').update? %>
|
166
|
+
<%= link_to "Edit post", edit_post_path(@post) %>
|
167
|
+
<% end %>
|
168
|
+
```
|
169
|
+
|
160
170
|
## Ensuring loyalties are used
|
161
171
|
|
162
172
|
Banken adds a method called `verify_authorized` to your controllers. This
|
@@ -192,7 +202,7 @@ end
|
|
192
202
|
```
|
193
203
|
|
194
204
|
If you need to perform some more sophisticated logic or you want to raise a custom
|
195
|
-
exception you can use the two lower level method `
|
205
|
+
exception you can use the two lower level method `banken_authorization_performed?` which
|
196
206
|
return `true` or `false` depending on whether `authorize!` have been called, respectively.
|
197
207
|
|
198
208
|
## Just plain old Ruby
|
data/lib/banken.rb
CHANGED
@@ -31,7 +31,7 @@ module Banken
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def authorize!(record=nil)
|
34
|
-
@
|
34
|
+
@_banken_authorization_performed = true
|
35
35
|
|
36
36
|
loyalty = loyalty(record)
|
37
37
|
unless loyalty.public_send(banken_query_name)
|
@@ -56,15 +56,21 @@ module Banken
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def skip_authorization
|
59
|
-
@
|
59
|
+
@_banken_authorization_performed = true
|
60
60
|
end
|
61
61
|
|
62
62
|
def verify_authorized
|
63
|
-
raise AuthorizationNotPerformedError unless
|
63
|
+
raise AuthorizationNotPerformedError unless banken_authorization_performed?
|
64
64
|
end
|
65
65
|
|
66
|
+
def banken_authorization_performed?
|
67
|
+
!!@_banken_authorization_performed
|
68
|
+
end
|
69
|
+
|
70
|
+
# @deprecated Use banken_authorization_performed? instead.
|
66
71
|
def banken_loyalty_authorized?
|
67
|
-
|
72
|
+
ActiveSupport::Deprecation.warn('banken_loyalty_authorized? is deprecated, use banken_authorization_performed? instead.')
|
73
|
+
banken_authorization_performed?
|
68
74
|
end
|
69
75
|
|
70
76
|
private
|
@@ -2,10 +2,10 @@ module Banken
|
|
2
2
|
class LoyaltyFinder
|
3
3
|
SUFFIX = "Loyalty"
|
4
4
|
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :controller_name
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@
|
7
|
+
def initialize(controller_name)
|
8
|
+
@controller_name = controller_name.to_s
|
9
9
|
end
|
10
10
|
|
11
11
|
def loyalty
|
@@ -15,14 +15,13 @@ module Banken
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def loyalty!
|
18
|
-
raise
|
19
|
-
loyalty || raise(NotDefinedError, "unable to find loyalty `#{loyalty_name}` for `#{controller}`")
|
18
|
+
loyalty || raise(NotDefinedError, "unable to find loyalty `#{loyalty_name}` for `#{controller_name}`")
|
20
19
|
end
|
21
20
|
|
22
21
|
private
|
23
22
|
|
24
23
|
def loyalty_name
|
25
|
-
"#{
|
24
|
+
"#{controller_name.camelize}#{SUFFIX}"
|
26
25
|
end
|
27
26
|
end
|
28
27
|
end
|
data/lib/banken/version.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: banken
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kyuden
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -133,6 +133,7 @@ files:
|
|
133
133
|
- ".gitignore"
|
134
134
|
- ".rspec"
|
135
135
|
- ".travis.yml"
|
136
|
+
- CHANGELOG.md
|
136
137
|
- CODE_OF_CONDUCT.md
|
137
138
|
- Gemfile
|
138
139
|
- LICENSE.txt
|
@@ -169,9 +170,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
170
|
version: '0'
|
170
171
|
requirements: []
|
171
172
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.
|
173
|
+
rubygems_version: 2.6.11
|
173
174
|
signing_key:
|
174
175
|
specification_version: 4
|
175
176
|
summary: Simple and lightweight authorization solution for Rails.
|
176
177
|
test_files: []
|
177
|
-
has_rdoc:
|