access-granted 0.2 → 0.2.1

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: 73df010b82397adef1ad1fbfdb345d0e5875ae86
4
- data.tar.gz: f6db604ca6be5fc22d24225728b700df5ed4db5b
3
+ metadata.gz: d6d610eeb4a1e57538d942c6f1cd0bfe6958a852
4
+ data.tar.gz: 50ce2232aa01528cb8478a38e578a8424ca0e801
5
5
  SHA512:
6
- metadata.gz: 98ae394fea6d7a5e4695e76746dc6e0701da2be4c21f9145edc979644e22faa2e3f5149bea758ee6799c2914e833d13bb678c051e7a8df8e35a6c42decae21a4
7
- data.tar.gz: 92f00c7b8668b51f25b4041022e26f095d65e302b79a5853aa500901dd851735b107336fa39e03899e4be723dd29fb78c7506a0e458737a89917e91fb1b831df
6
+ metadata.gz: 0768c9dd24d77292180d8574f9155312c3a4028b2259d8125d8db36754e8a26c7bb448f88452f2b7588fa72edd9e46d68522ea1a3eb6e3a2b185ef766ecc292d
7
+ data.tar.gz: 7852d05613d5afa58e5cf6aa23a0432efab48ba0b7badc812047a107543e1c9784492ed591547e5f3cb649a0f58e2f53f75b8c1f964741451053eaea72111c49
data/README.md CHANGED
@@ -12,22 +12,22 @@ Multi-role and whitelist based authorization gem for Rails. And it's lightweight
12
12
 
13
13
  ### Supported Ruby versions
14
14
 
15
- Guaranteed to work on all major Ruby versions MRI 1.9.3-2.2, Rubinius >= 2.X and JRuby >= 1.7.
15
+ Because it has **zero** runtime dependencies it is guaranteed to work on all major Ruby versions MRI 1.9.3-2.2, Rubinius >= 2.X and JRuby >= 1.7.
16
16
 
17
17
  ## Summary
18
18
 
19
- AccessGranted is meant as a replacement for CanCan to solve three major problems:
19
+ AccessGranted is meant as a replacement for CanCan to solve major problems:
20
20
 
21
21
  1. Performance
22
- On average AccessGranted is 50-60% faster in resolving identical dependencies and takes less memory.
23
- See [benchmarks](https://github.com/chaps-io/access-granted/blob/master/benchmarks).
24
22
 
25
- 2. Built-in support for user roles
23
+ On average AccessGranted is 50-60% faster in resolving identical permissions and takes less memory.
24
+ See [benchmarks](https://github.com/chaps-io/access-granted/blob/master/benchmarks).
26
25
 
27
- Easy to read access policy code where permissions are cleanly grouped into roles.
28
- Additionally, permissions are forced to be unique in the scope of a role. This greatly simplifies resolving permissions and makes it faster.
26
+ 2. Roles
29
27
 
30
- 3. white-list based
28
+ Adds support for roles, so no more `if`'s and `else`'s in your Policy file. This makes it extremely easy to maintain and read the code.
29
+
30
+ 3. white-lists
31
31
 
32
32
  This means that you define what the user **can** do, which results in clean, readable policies regardless of app complexity.
33
33
  You don't have to worry about juggling `can`s and `cannot`s in a very convoluted way!
@@ -37,7 +37,7 @@ AccessGranted is meant as a replacement for CanCan to solve three major problems
37
37
  4. framework agnostic
38
38
 
39
39
  Permissions can work on basically any object and AccessGranted is framework-agnostic,
40
- but it has Rails support of out the box :)
40
+ but it has Rails support out of the box :)
41
41
  It **does not depend on any libraries**, pure and clean Ruby code. Guaranteed to always work,
42
42
  even when software around changes.
43
43
 
@@ -88,7 +88,7 @@ end
88
88
  #### Defining roles
89
89
 
90
90
  Each `role` method accepts the name of the role you're creating and an optional matcher.
91
- Matchers are used to check if user belongs to that role and if the permissions inside should be executed against him.
91
+ Matchers are used to check if user belongs to that role and if the permissions inside should be executed against it.
92
92
 
93
93
  The simplest role can be defined as follows:
94
94
 
@@ -115,8 +115,8 @@ role :member do
115
115
  end
116
116
  ```
117
117
 
118
- The `{ is_admin: true }` hash is compared with the user's attributes to see if the role should be applied to him.
119
- So, if the user has an attribute `is_admin` set to `true`, then the role will be applied to him.
118
+ The `{ is_admin: true }` hash is compared with the user's attributes to see if the role should be applied to it.
119
+ So, if the user has an attribute `is_admin` set to `true`, then the role will be applied to it.
120
120
 
121
121
  **Note:** you can use more keys in the hash to check many attributes at once.
122
122
 
@@ -133,8 +133,8 @@ end
133
133
 
134
134
  #### Block conditions
135
135
 
136
- "But wait! User should also be able to edit his posts, and only his posts!" you are wondering.
137
- This can be done using a block condition in `can` method, like this:
136
+ "But wait! User should also be able to edit his posts, and only his posts!", you are wondering.
137
+ This can be done using a block condition in `can` method, like so:
138
138
 
139
139
  ```ruby
140
140
  role :member do
@@ -144,11 +144,11 @@ role :member do
144
144
  end
145
145
  ```
146
146
 
147
- When the given block evaluates to `true`, the user is then given the permission to update the post.
147
+ When the given block evaluates to `true`, then user is given the permission to update the post.
148
148
 
149
149
  #### Roles in order of importance
150
150
 
151
- Additionally we can allow admins to update **all** posts despite them not being authors like this:
151
+ Additionally, we can allow admins to update **all** posts despite them not being authors like so:
152
152
 
153
153
 
154
154
  ```ruby
@@ -218,6 +218,7 @@ class UsersController
218
218
  # (...)
219
219
  end
220
220
  end
221
+ ```
221
222
 
222
223
  #### Checking permissions in views
223
224
 
@@ -234,7 +235,7 @@ You can hide any part of the page from users without permissions like this:
234
235
 
235
236
  #### Customizing policy
236
237
 
237
- By default AccessGranted adds this method to your controllers:
238
+ By default, AccessGranted adds this method to your controllers:
238
239
 
239
240
  ```ruby
240
241
  def current_policy
@@ -242,7 +243,7 @@ By default AccessGranted adds this method to your controllers:
242
243
  end
243
244
  ```
244
245
 
245
- If you have a different policy class or if your user is not stored in `current_user` variable, then you can override it in any controllers and modify the logic as you please.
246
+ If you have a different policy class or if your user is not stored in `current_user` variable, then you can override it in any controller and modify the logic as you please.
246
247
 
247
248
  You can even have different policies for different controllers!
248
249
 
@@ -311,7 +312,7 @@ end
311
312
 
312
313
  ## Compatibility with CanCan
313
314
 
314
- This gem was created as a replacement for CanCan and therefore it requires minimum work to switch.
315
+ This gem has been created as a replacement for CanCan and therefore it requires minimum work to switch.
315
316
 
316
317
  ### Main differences
317
318
 
@@ -322,10 +323,10 @@ This gem was created as a replacement for CanCan and therefore it requires minim
322
323
 
323
324
  2. Both `can?`/`cannot?` and `authorize!` methods work in Rails controllers and views, just like in CanCan.
324
325
  The only change you have to make is to replace all `can? :manage, Class` with the exact action to check against.
325
- `can :manage` is still available for **defining** methods and serves as a shortcut for defining `:read`, `:create`, `:update`, `:destroy` all in one line.
326
+ `can :manage` is still available for **defining** methods and serves as a shortcut for defining `:create`, `:read`, `:update`, `:destroy` all in one line.
326
327
 
327
328
  3. Syntax for defining permissions in AccessPolicy file (Ability in CanCan) is exactly the same,
328
- with added roles on top. See [Usage](#usage) below.
329
+ with roles added on top. See [Usage](#usage) below.
329
330
 
330
331
 
331
332
  ## Contributing
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "access-granted"
7
- spec.version = "0.2"
7
+ spec.version = "0.2.1"
8
8
  spec.authors = ["Piotrek Okoński"]
9
9
  spec.email = ["piotrek@okonski.org"]
10
10
  spec.description = %q{Role based authorization gem}
@@ -1,6 +1,6 @@
1
1
  # Benchmark results
2
2
 
3
- Benchmarks ran on Ubuntu 15.10 64bit, i5 2500k @ 4.4Ghz, 16 GB RAM with Ruby 2.2.
3
+ Benchmarks ran on Ubuntu 15.04 64bit, i5 2500k @ 4.4Ghz, 16 GB RAM with Ruby 2.2.
4
4
 
5
5
  ## permissions.rb
6
6
 
@@ -13,3 +13,9 @@ if defined? ActionController::Base
13
13
  include AccessGranted::Rails::ControllerMethods
14
14
  end
15
15
  end
16
+
17
+ if defined? ActionController::API
18
+ ActionController::API.class_eval do
19
+ include AccessGranted::Rails::ControllerMethods
20
+ end
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: access-granted
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotrek Okoński