rails_authorize 0.1.1 → 1.0.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: c1ca7bca03c197c26fa619fce7395a12cb0b06af518f23fad35a31b48354ee1b
4
- data.tar.gz: 53daf5e713992e4a6df34287479041d4e7485f07792f4eef8fb3f02a73728798
3
+ metadata.gz: e8f0d5120896348f98b7f268593565d38a58b12478fdb9b622f429fcf76eaa28
4
+ data.tar.gz: 163ad731aaeaaaf3d766abc3de284f65a12e1d507e2bf67a02be8a090d25cd6e
5
5
  SHA512:
6
- metadata.gz: da4b1a4adcc5c2d878396b0d285643ccfcb48e0317de455d16da11a1144c7d5dca8bff30b834289566fb2ec72d4191d729beaa36ec26b03b80f99f7bfb5c0dc8
7
- data.tar.gz: c67ee8340c91d5df33b5158776d5b215c727ff5307ea004cac1e862595195d109c66fb90d1750e3d0888180773d083347f4bb63fd66dc7665bdce038ab594534
6
+ metadata.gz: f2ca97240e596d0a505edda8fe402f27cc2161648a166127b84e394eb111d2562b434fb0c71b08af64b2d541071b5a8017dcfcb7a22b34fcf91599f044e74790
7
+ data.tar.gz: 3ff394b863f95512dfd0ef6b9889ab8b5153ce452bff9a8c73f32573a9deca451004dda547f8c5f8255976b051e37049b958b9679749572d257d7687b9ba146d
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_authorize (0.1.1)
4
+ rails_authorize (1.0.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -32,9 +32,9 @@ end
32
32
  ```
33
33
 
34
34
  ```ruby
35
- # app/authorizations/application_authorization.rb
35
+ # app/policies/application_policy.rb
36
36
 
37
- class ApplicationAuthorization
37
+ class ApplicationPolicy
38
38
  attr_reader :user, :target, :context
39
39
 
40
40
  def initialize(user, target, context)
@@ -46,9 +46,9 @@ end
46
46
  ```
47
47
 
48
48
  ```ruby
49
- # app/authorizations/post_authorization.rb
49
+ # app/policies/post_policy.rb
50
50
 
51
- class PostAuthorization < ApplicationAuthorization
51
+ class PostPolicy < ApplicationPolicy
52
52
  def index?
53
53
  true
54
54
  end
@@ -67,7 +67,7 @@ end
67
67
  # app/controllers/application_controller.rb
68
68
 
69
69
  class ApplicationController < ActionController::Base
70
- include RailsAuthorization
70
+ include RailsAuthorize
71
71
  end
72
72
  ```
73
73
 
@@ -5,19 +5,19 @@ module RailsAuthorize
5
5
  class NotAuthorizedError < StandardError; end
6
6
 
7
7
  ##
8
- # Finds authorization class for given target and returns new instance
8
+ # Finds policy class for given target and returns new instance
9
9
  #
10
- # @param target [any] the target to load authorization
11
- # @param options [Hash] key/value options (user, authorization, context)
10
+ # @param target [any] the target to load policy
11
+ # @param options [Hash] key/value options (user, policy, context)
12
12
  # @param options[:user] [Object] the user that initiated the action
13
- # @param options[:authorization] [Class] Authorization class to use for authenticate
14
- # @param options[:context] [Hash] other key/value options to use in the authorization methods
13
+ # @param options[:policy] [Class] Authorization class to use for authenticate
14
+ # @param options[:context] [Hash] other key/value options to use in the policy methods
15
15
  #
16
- # @return [Object] new authorization instance
16
+ # @return [Object] new policy instance
17
17
  #
18
- def authorization(target, options={})
18
+ def policy(target, options={})
19
19
  user = options[:user] || current_user
20
- klass = options[:authorization] || "#{target.model_name.name}Authorization".constantize
20
+ klass = options[:policy] || "#{target.model_name.name}Policy".constantize
21
21
 
22
22
  klass.new(user, target, options[:context])
23
23
  end
@@ -26,49 +26,49 @@ module RailsAuthorize
26
26
  # Throwing an error if the user is not authorized to perform the given action
27
27
  #
28
28
  # @param target [Object] the target we're checking permissions of
29
- # @param options [Hash] key/value options (action, user, authorization, context)
30
- # @param options[:action] [String] the method to check on the authorization (e.g. `:show?`)
29
+ # @param options [Hash] key/value options (action, user, policy, context)
30
+ # @param options[:action] [String] the method to check on the policy (e.g. `:show?`)
31
31
  #
32
32
  # @raise [NotAuthorizedError] if the given action method returned false
33
33
  # @return [Object] the passed target
34
34
  #
35
35
  def authorize(target, options={})
36
36
  action = options.delete(:action) || "#{action_name}?"
37
- authorization = authorization(target, options)
37
+ policy = policy(target, options)
38
38
 
39
- raise(NotAuthorizedError) unless authorization.public_send(action)
39
+ raise(NotAuthorizedError) unless policy.public_send(action)
40
40
 
41
41
  target
42
42
  end
43
43
 
44
44
  ##
45
- # Retrieves the authorization scope for the given target
45
+ # Retrieves the policy scope for the given target
46
46
  #
47
47
  # @param target [Object] the target we're retrieving the policy scope for
48
- # @param options [Hash] key/value options (user, authorization, context)
48
+ # @param options [Hash] key/value options (user, policy, context)
49
49
  #
50
- # @return [Scope] authorized scope
50
+ # @return [Scope] policy scope
51
51
  #
52
- def authorization_scope(target, options={})
53
- authorization(target, options).scope
52
+ def policy_scope(target, options={})
53
+ policy(target, options).scope
54
54
  end
55
55
 
56
56
  ##
57
57
  # Throwing an error if the user is not authorized to perform the given action
58
58
  #
59
59
  # @param target [Object] the target we're retrieving the policy scope for
60
- # @param options [Hash] key/value options (action, user, authorization, context)
61
- # @param options[:action] [String] the method to check on the authorization (e.g. `:show?`)
60
+ # @param options [Hash] key/value options (action, user, policy, context)
61
+ # @param options[:action] [String] the method to check on the policy (e.g. `:show?`)
62
62
  #
63
63
  # @raise [NotAuthorizedError] if the given action method returned false
64
- # @return [Scope] authorization scope
64
+ # @return [Scope] authorized policy scope
65
65
  #
66
66
  def authorized_scope(target, options={})
67
67
  action = options.delete(:action) || "#{action_name}?"
68
- authorization = authorization(target, options)
68
+ policy = policy(target, options)
69
69
 
70
- raise(NotAuthorizedError) unless authorization.public_send(action)
70
+ raise(NotAuthorizedError) unless policy.public_send(action)
71
71
 
72
- authorization.scope
72
+ policy.scope
73
73
  end
74
74
  end
@@ -1,3 +1,3 @@
1
1
  module RailsAuthorize
2
- VERSION = "0.1.1"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_authorize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rjurado01
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-10 00:00:00.000000000 Z
11
+ date: 2018-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler