role_authorization 0.9.1 → 0.9.2

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: 4d1c4328441ef2d5ecee3d451c844d4068b99d79
4
- data.tar.gz: 880716b15c5e0a370c83b85e3b9e9c579e2c3634
3
+ metadata.gz: 2b82cc6cf70a1dae2b60c08fbbebe3b7eddd8f91
4
+ data.tar.gz: 76e2bcfe4b15319db70d96923de9f5572a90b6d8
5
5
  SHA512:
6
- metadata.gz: 49207b05f38eca3c7011fbd92378ecda1ff575245962a469d2087e070e7327a0b40c1bc855d08f843dbe18b501f3c1010b19637ed3d488867bfecd597773c032
7
- data.tar.gz: 4f62169cc3790715c4a22193acfd70e57086f9f6045b8ff2710706cf73c84e0561fd94fafe3ad62aa91ef68afc75770f4d85409a0bc8ce94694d4d3a009b563b
6
+ metadata.gz: 346377c85cd0992b85de06973c5835012e9180e7e185b37c1f6b83d7a1d26a8bda10ee70b5f0133be72a0e2525dc8c400e0a9c6a8ce40595dba7ef0fedae6a8a
7
+ data.tar.gz: 7f018b62080f8eb3b0d85eb3dfb1fbdd5ca742479fb46a7658fb41a6e5dbfd9aa8d02efe602d1ee9d17e4ed023acc788c8533d8bcdd960a860b70ba2be654bca
@@ -16,6 +16,20 @@ module RoleAuthorization
16
16
  end
17
17
 
18
18
  module InstanceMethods
19
+ def unserialized_user_ids
20
+ result = if Rails::VERSION::MAJOR >= 4
21
+ self.user_ids.unserialized_value
22
+ else
23
+ self.user_ids
24
+ end
25
+
26
+ if result.is_a?(Hash)
27
+ result
28
+ else
29
+ Hash.new
30
+ end
31
+ end
32
+
19
33
  def scope_with(scope)
20
34
  if scope.blank? || scope.is_a?(Symbol) || scope.is_a?(String) || scope.is_a?(Integer)
21
35
  scope || :all
@@ -30,45 +44,45 @@ module RoleAuthorization
30
44
  []
31
45
  else
32
46
  if scope.nil?
33
- RoleAuthorization::Roles::Manager.user_klass.where(:id => user_ids.values.flatten.uniq).all
47
+ RoleAuthorization::Roles::Manager.user_klass.where(:id => unserialized_user_ids.values.flatten.uniq).all
34
48
  else
35
- RoleAuthorization::Roles::Manager.user_klass.where(:id => user_ids[scope_with(scope)]).all
49
+ RoleAuthorization::Roles::Manager.user_klass.where(:id => unserialized_user_ids[scope_with(scope)]).all
36
50
  end
37
51
  end
38
52
  end
39
53
 
40
54
  def add_user(user_id, scope = nil)
41
- unserialized_user_ids = self.user_ids
42
- unserialized_user_ids ||= Hash.new
55
+ hash = unserialized_user_ids
56
+ hash ||= Hash.new
43
57
 
44
58
  if scope.nil? || scope.is_a?(Symbol) || scope.is_a?(String) || scope.is_a?(Class)
45
- unserialized_user_ids[scope_with(scope)] ||= Array.new
46
- unserialized_user_ids[scope_with(scope)] << user_id
47
- unserialized_user_ids[scope_with(scope)].uniq!
59
+ hash[scope_with(scope)] ||= Array.new
60
+ hash[scope_with(scope)] << user_id
61
+ hash[scope_with(scope)].uniq!
48
62
  else
49
- unserialized_user_ids[scope_with(scope)] ||= Array.new
50
- unserialized_user_ids[scope_with(scope)] << user_id
51
- unserialized_user_ids[scope_with(scope)].uniq!
63
+ hash[scope_with(scope)] ||= Array.new
64
+ hash[scope_with(scope)] << user_id
65
+ hash[scope_with(scope)].uniq!
52
66
  end
53
67
 
54
- self.user_ids = unserialized_user_ids
68
+ self.user_ids = hash
55
69
 
56
70
  save
57
71
  end
58
72
 
59
73
  def remove_user(user_id, scope = nil)
60
- unserialized_user_ids = self.user_ids
61
- unserialized_user_ids ||= Hash.new
74
+ hash = unserialized_user_ids
75
+ hash ||= Hash.new
62
76
 
63
77
  if scope.nil? || scope.is_a?(Symbol) || scope.is_a?(String) || scope.is_a?(Class)
64
- unserialized_user_ids[scope_with(scope)] ||= Array.new
65
- unserialized_user_ids[scope_with(scope)].delete(user_id)
78
+ hash[scope_with(scope)] ||= Array.new
79
+ hash[scope_with(scope)].delete(user_id)
66
80
  else
67
- unserialized_user_ids[scope_with(scope)] ||= Array.new
68
- unserialized_user_ids[scope_with(scope)].delete(user_id)
81
+ hash[scope_with(scope)] ||= Array.new
82
+ hash[scope_with(scope)].delete(user_id)
69
83
  end
70
84
 
71
- self.user_ids = unserialized_user_ids
85
+ self.user_ids = hash
72
86
 
73
87
  save
74
88
  end
@@ -1,3 +1,3 @@
1
1
  module RoleAuthorization
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: role_authorization
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John 'asceth' Long