ratify 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +45 -49
- data/lib/ratify/permission.rb +2 -0
- data/lib/ratify/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6125cbd00b941e2729093dc320915ecccc5e884b2ec81e71e3c4c1ff2c1b179e
|
4
|
+
data.tar.gz: df8189df02387d8290f636255acb95307dbec7bb7e8709b30daa10c4801327eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3dbcf2a8831078a41e74c4473c2cf81c70c0f01ab568483fdee4cd977c4eb81a4b4b2a4b64013fac6470efeeb0a996d9ffc9777d578807f0e0e74e0e77fbf712
|
7
|
+
data.tar.gz: 293148aeef71b3da92207141d9abf61e945062b317a2d11c31bb7cc9c383613e1284478122e9e5f10aaf2d7aba980daf4c03f5d3bb16bf747248e73ea127fbeb
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,73 +1,69 @@
|
|
1
1
|
# Ratify
|
2
2
|
|
3
|
-
|
3
|
+
Ratify is a very fast, easy to use, zero-dependency Ruby authorization gem.
|
4
|
+
Simply include the `Ratify` module in your class to give it permissions. You
|
5
|
+
can check the permissions on a class or instance level with the `permit?`
|
6
|
+
method.
|
4
7
|
|
5
|
-
|
8
|
+
Ratify makes as few assumptions about your authorization stragegy as possible.
|
9
|
+
It knows only that you have one object that needs permission to be accessed
|
10
|
+
by another object. You can optionally provide a list of actions and/or
|
11
|
+
conditions as well.
|
6
12
|
|
7
|
-
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'ratify'
|
11
|
-
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install ratify
|
20
|
-
|
21
|
-
## Usage
|
22
|
-
|
23
|
-
Here's an example of how you can use Ratify for basic user permissions.
|
13
|
+
Here's a very simple user-authorization example:
|
24
14
|
|
25
15
|
```ruby
|
26
16
|
class User
|
27
17
|
attr_accessor :admin
|
28
|
-
|
29
|
-
def initialize(admin: false)
|
30
|
-
@admin = admin
|
31
|
-
end
|
32
|
-
|
33
|
-
def admin?
|
34
|
-
admin && true
|
35
|
-
end
|
36
18
|
end
|
37
19
|
|
38
20
|
class Record
|
39
21
|
include Ratify
|
40
|
-
|
41
|
-
# Admins have full access to the records.
|
42
|
-
permit User, :create, :update, if: :admin?
|
43
22
|
|
44
|
-
|
45
|
-
|
23
|
+
attr_accessor :published, :user
|
24
|
+
|
25
|
+
# Admins have full access to any record.
|
26
|
+
permit :User, :full_access, if: -> (user) { user.admin }
|
27
|
+
|
28
|
+
# Users have full access to their own records.
|
29
|
+
permit :User, :full_access, if: -> (user) { self.user == user }
|
30
|
+
|
31
|
+
# Signed in users can create new records.
|
32
|
+
permit :User, :create
|
46
33
|
|
47
|
-
#
|
48
|
-
permit
|
34
|
+
# Signed out users can read published records.
|
35
|
+
permit nil, :read, if: :published
|
36
|
+
end
|
37
|
+
```
|
49
38
|
|
50
|
-
|
39
|
+
The permissions can be read at a class-level:
|
51
40
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
41
|
+
```ruby
|
42
|
+
Record.permit?(current_user, :create)
|
43
|
+
```
|
56
44
|
|
57
|
-
|
58
|
-
user1 = User.new
|
59
|
-
user2 = User.new
|
60
|
-
record = Record.new(user: user1)
|
45
|
+
or on an instance-level:
|
61
46
|
|
62
|
-
|
63
|
-
record.
|
64
|
-
|
47
|
+
```ruby
|
48
|
+
record.permit?(current_user, :update)
|
49
|
+
```
|
50
|
+
|
51
|
+
## Installation
|
52
|
+
|
53
|
+
Add this line to your application's Gemfile:
|
65
54
|
|
66
|
-
|
67
|
-
|
68
|
-
Record.permits?(user2, :create) # => true
|
55
|
+
```ruby
|
56
|
+
gem 'ratify'
|
69
57
|
```
|
70
58
|
|
59
|
+
And then execute:
|
60
|
+
|
61
|
+
$ bundle
|
62
|
+
|
63
|
+
Or install it yourself as:
|
64
|
+
|
65
|
+
$ gem install ratify
|
66
|
+
|
71
67
|
## Development
|
72
68
|
|
73
69
|
After checking out the repo, run `bin/setup` to install dependencies. Then,
|
data/lib/ratify/permission.rb
CHANGED
@@ -27,6 +27,8 @@ class Permission
|
|
27
27
|
# @param [Array<Symbol>] actions
|
28
28
|
# @return [true | false] If the given actions are all in the permission.
|
29
29
|
def action_matches?(actions)
|
30
|
+
self.actions.include?(:full_access) ||
|
31
|
+
|
30
32
|
actions.all? { |action| self.actions.include?(action) }
|
31
33
|
end
|
32
34
|
|
data/lib/ratify/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ratify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Haynes
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|