ratify 0.1.0 → 0.2.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
  SHA256:
3
- metadata.gz: 0cebc395d3d5455371bcf40a2b097824d2fbf140504ceb819c47bf14dd3073a9
4
- data.tar.gz: 70546ffb22562b86524567219f50a838b9af387ce5f3d9a8c21848347fdf7e27
3
+ metadata.gz: 6125cbd00b941e2729093dc320915ecccc5e884b2ec81e71e3c4c1ff2c1b179e
4
+ data.tar.gz: df8189df02387d8290f636255acb95307dbec7bb7e8709b30daa10c4801327eb
5
5
  SHA512:
6
- metadata.gz: 9853b5ffeb4911df6ffa060e6c705b19f5fa201d0877991393e164e3645a815fe084a24ad54d886bb3399e8f84f38ebc63fe0170a8b6aa9d686c8e4f4deb0d75
7
- data.tar.gz: 2e4c8c4d4923eab0a19934cfaf65c6c22b68e933f8cc2ba855bf2663257c79ffbac7638c5d0cddcb4a5fda77132288a062cff91ec1634b36d318e2901cefb8a0
6
+ metadata.gz: 3dbcf2a8831078a41e74c4473c2cf81c70c0f01ab568483fdee4cd977c4eb81a4b4b2a4b64013fac6470efeeb0a996d9ffc9777d578807f0e0e74e0e77fbf712
7
+ data.tar.gz: 293148aeef71b3da92207141d9abf61e945062b317a2d11c31bb7cc9c383613e1284478122e9e5f10aaf2d7aba980daf4c03f5d3bb16bf747248e73ea127fbeb
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ratify (0.1.0)
4
+ ratify (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,73 +1,69 @@
1
1
  # Ratify
2
2
 
3
- An easy to use, zero-dependency authorization gem.
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
- ## Installation
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
- Add this line to your application's Gemfile:
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
- # Users can create new records.
45
- permit User, :create
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
- # Users can update and destroy their own records.
48
- permit User, :update, :destroy, if: -> (user) { self.user == user }
34
+ # Signed out users can read published records.
35
+ permit nil, :read, if: :published
36
+ end
37
+ ```
49
38
 
50
- attr_accessor :user
39
+ The permissions can be read at a class-level:
51
40
 
52
- def initialize(user)
53
- @user = user
54
- end
55
- end
41
+ ```ruby
42
+ Record.permit?(current_user, :create)
43
+ ```
56
44
 
57
- admin = User.new(admin: true)
58
- user1 = User.new
59
- user2 = User.new
60
- record = Record.new(user: user1)
45
+ or on an instance-level:
61
46
 
62
- record.permits?(admin, :create) # => true
63
- record.permits?(user1, :update) # => true
64
- record.permits?(user2, :destroy) # => false
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
- Record.permits?(admin, :create) # => true
67
- Record.permits?(user1, :create) # => true
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,
@@ -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
 
@@ -1,4 +1,4 @@
1
1
  module Ratify
2
2
  # The gem's semantic version.
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
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.1.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-26 00:00:00.000000000 Z
11
+ date: 2018-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler