role_authorization 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,7 @@ RoleAuthorization::Rules.define :role do
8
8
  else
9
9
  scope = if options[:scope]
10
10
  if options[:scope].is_a?(Proc)
11
- instance_eval(&options[:scope])
11
+ controller_instance.instance_eval(&options[:scope])
12
12
  else
13
13
  options[:scope]
14
14
  end
@@ -21,18 +21,22 @@ RoleAuthorization::Rules.define :role do
21
21
  end
22
22
 
23
23
  RoleAuthorization::Rules.define :user do
24
- resource = controller_instance.instance_variable_get("@#{options[:resource]}".to_sym)
25
-
26
- if resource.nil?
24
+ if controller_instance.current_user.blank?
27
25
  false
28
26
  else
29
- controller_instance.current_user.try(:id) == resource.try(options[:check])
27
+ if options[:resource]
28
+ check_method = options[:check] || :id
29
+ resource_instance = controller_instance.instance_eval(&options[:resource])
30
+ controller_instance.current_user.id == resource_instance.try(check_method)
31
+ else
32
+ false
33
+ end
30
34
  end
31
35
  end
32
36
 
33
37
  RoleAuthorization::Rules.define :custom do
34
38
  unless options[:block].nil?
35
- true if options[:block].call(controller_instance) == true
39
+ true if controller_instance.instance_eval(&options[:block]) == true
36
40
  else
37
41
  false
38
42
  end
@@ -1,3 +1,3 @@
1
1
  module RoleAuthorization
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: role_authorization
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.3
5
+ version: 0.3.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - John 'asceth' Long