role_authorization 0.9.2 → 0.9.3

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: 2b82cc6cf70a1dae2b60c08fbbebe3b7eddd8f91
4
- data.tar.gz: 76e2bcfe4b15319db70d96923de9f5572a90b6d8
3
+ metadata.gz: 8dc19823edcfd347a5c7be4b26940b762a0f26ec
4
+ data.tar.gz: 953fdc032983b7311a0cdfdd451c342e10126d83
5
5
  SHA512:
6
- metadata.gz: 346377c85cd0992b85de06973c5835012e9180e7e185b37c1f6b83d7a1d26a8bda10ee70b5f0133be72a0e2525dc8c400e0a9c6a8ce40595dba7ef0fedae6a8a
7
- data.tar.gz: 7f018b62080f8eb3b0d85eb3dfb1fbdd5ca742479fb46a7658fb41a6e5dbfd9aa8d02efe602d1ee9d17e4ed023acc788c8533d8bcdd960a860b70ba2be654bca
6
+ metadata.gz: a2436729de7b0d3962e422d69da2e9e75e5aeef3fcd124486923fe93e6e4d3df8554520cfbc63b61328909acfbbd64a3c36ce3fcbde3d74355bed171530f99d0
7
+ data.tar.gz: afa1a08c1a306b72425f9f1138624f3efc11c8d64abdb6b7a204f4bc3489183da2872a9ece9ebfc6830c1a24931efa075518dcdfeac2866337fe46888c3edadc
@@ -14,11 +14,24 @@ module RoleAuthorization
14
14
  @groups = Hash.new
15
15
  @creations = Hash.new(Array.new)
16
16
  @nicknames = Hash.new {|hash, key| key}
17
+ @cache_user_ids = false
17
18
 
18
19
  self
19
20
  end
20
21
 
21
22
  module InstanceMethods
23
+ def cache_user(role_name, user_id, scope)
24
+ if @cache_user_ids
25
+ role(role_name).add_user(user_id)
26
+ end
27
+ end
28
+
29
+ def uncache_user(role_name, user_id)
30
+ if @cache_user_ids
31
+ role(role_name).remove_user(user_id)
32
+ end
33
+ end
34
+
22
35
  def role(role_name)
23
36
  @_role ||= {}
24
37
  @_role[role_name] ||= klass.find_by_name(role_name)
@@ -34,6 +47,10 @@ module RoleAuthorization
34
47
  end
35
48
  end
36
49
 
50
+ def cache(value)
51
+ @cache_user_ids = value
52
+ end
53
+
37
54
  def roles(*options)
38
55
  @global_roles, @object_roles = if options.last.is_a?(Hash)
39
56
  [options.pop, options].reverse
@@ -18,7 +18,11 @@ module RoleAuthorization
18
18
  module InstanceMethods
19
19
  def unserialized_user_ids
20
20
  result = if Rails::VERSION::MAJOR >= 4
21
- self.user_ids.unserialized_value
21
+ if self.user_ids.is_a?(Hash)
22
+ self.user_ids
23
+ else
24
+ self.user_ids.unserialized_value
25
+ end
22
26
  else
23
27
  self.user_ids
24
28
  end
@@ -94,7 +94,7 @@ module RoleAuthorization
94
94
  self.serialized_roles ||= Hash.new
95
95
 
96
96
  (self.serialized_roles[:global] || []).map do |role_name|
97
- RoleAuthorization::Roles.manager.role(role_name).remove_user(self.id)
97
+ RoleAuthorization::Roles.manager.uncache_user(role_name, self.id)
98
98
  end
99
99
  self.serialized_roles[:global] = Array.new
100
100
 
@@ -123,7 +123,7 @@ module RoleAuthorization
123
123
  end
124
124
 
125
125
  if save(:validate => false)
126
- RoleAuthorization::Roles.manager.role(role_name).add_user(self.id, scope)
126
+ RoleAuthorization::Roles.manager.cache_user(role_name, self.id, scope)
127
127
  true
128
128
  else
129
129
  false
@@ -151,7 +151,7 @@ module RoleAuthorization
151
151
  end
152
152
 
153
153
  if save(:validate => false)
154
- RoleAuthorization::Roles.manager.role(role_name).remove_user(self.id, scope)
154
+ RoleAuthorization::Roles.manager.uncache_user(role_name, self.id, scope)
155
155
  true
156
156
  else
157
157
  false
@@ -1,3 +1,3 @@
1
1
  module RoleAuthorization
2
- VERSION = "0.9.2"
2
+ VERSION = "0.9.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: role_authorization
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John 'asceth' Long
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-30 00:00:00.000000000 Z
11
+ date: 2014-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec