infopark_reactor 1.15.0.beta1 → 1.16.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
  SHA1:
3
- metadata.gz: a56b31ba2e29489af380f651342ddc82f3b542d3
4
- data.tar.gz: 9ed150774b911bb3dfb2c311d7a84dff1dc4fd72
3
+ metadata.gz: 9d51a7c5afd4000ea8e81db0087cc71d2b7dddaf
4
+ data.tar.gz: ee5eb6afd1de7fb108017e7a82d3bb27f9990acc
5
5
  SHA512:
6
- metadata.gz: 78174cc1ebf120f5f844e1ebcb26c1f1e4245cb63bd03540bca50a380e455717c11580e4607a62e2406f1392991f1686670e7d39b5930259b598f3290dc3b134
7
- data.tar.gz: 4faab19e5c534b811533d7a106057c03ed9fc2cff51fc70013a1743d2460db98e05ca12aa8d04bae89bedea2e4c3c3defc9004eb1afb2a2dd0884eeeba889ca4
6
+ metadata.gz: d221067cab1005f0735f2cdc346c26b72268281c45a08340158a03716938aead93f94b5da7d58a71263e2b40c20cb3ba5476e9279aa7756b3ae834484e0cce6e
7
+ data.tar.gz: 880558efbed693fed5b80eab63ce1c479c5b4df8f2d147f5106fd86574e6ad86c81e802b60e2c47f16b1465a234f221d58345bcaff2cdda109e96efdb7b777dd
@@ -1,36 +1,34 @@
1
1
  # -*- encoding : utf-8 -*-
2
- require 'singleton'
3
2
 
4
3
  module Reactor
5
4
  module Cache
6
5
  class Permission
7
- include Singleton
6
+ BACKING_CACHE_EXPIRATION = 5
8
7
 
9
- def lookup(user, key, &block)
10
- set(user, key, yield) unless set?(user, key)
11
- get(user, key)
8
+ def self.instance
9
+ self.new
12
10
  end
13
11
 
14
12
  def initialize
15
- @cache = {}
16
- end
17
-
18
- def invalidate(user)
19
- @cache[user] = {}
13
+ @@backing_storage ||= ActiveSupport::Cache::MemoryStore.new({ size: 1.megabyte })
20
14
  end
21
15
 
22
- protected
23
- def set?(user, key)
24
- @cache.key?(user) && @cache[user].include?(key)
16
+ def lookup(user, key, &block)
17
+ cache_entry = @@backing_storage.fetch(user.to_s, :expires_in => BACKING_CACHE_EXPIRATION.minutes) do
18
+ {key => block.call}
19
+ end
20
+ if cache_entry.key?(key)
21
+ cache_entry[key]
22
+ else
23
+ result = block.call
24
+ @@backing_storage.write(user.to_s, cache_entry.merge({key => result}), :expires_in => BACKING_CACHE_EXPIRATION.minutes)
25
+ result
26
+ end
25
27
  end
26
28
 
27
- def set(user, key, value)
28
- @cache[user] ||= {}
29
- @cache[user][key] = value
30
- end
31
29
 
32
- def get(user, key)
33
- @cache[user][key]
30
+ def invalidate(user)
31
+ @@backing_storage.delete(user.to_s)
34
32
  end
35
33
  end
36
34
  end
@@ -1,38 +1,36 @@
1
1
  # -*- encoding : utf-8 -*-
2
- require 'singleton'
3
2
 
4
3
  module Reactor
5
4
  module Cache
6
5
  class User
7
- include Singleton
6
+ BACKING_CACHE_EXPIRATION = 5
7
+
8
+ def self.instance
9
+ self.new
10
+ end
11
+
12
+ def initialize
13
+ @@backing_storage ||= ActiveSupport::Cache::MemoryStore.new({ size: 1.megabyte })
14
+ end
8
15
 
9
16
  def get(user_name)
10
17
  @cache ||= {}
11
18
  # Rails.logger.debug "User:Cache hit: #{hit?(user_name.to_s)} [#{@cache[user_name.to_s].inspect}]"
12
19
 
13
20
  key = user_name.to_s
14
- if hit?(key)
15
- @cache[key]
16
- else
17
- @cache[key] = Reactor::Session::User.new(key)
21
+ @@backing_storage.fetch(key, :expires_in => BACKING_CACHE_EXPIRATION.minutes) do
22
+ Reactor::Session::User.new(key)
18
23
  end
19
24
  end
20
25
 
21
26
  def set(user_name, user)
22
- @cache ||= {}
23
- @cache[user_name.to_s] = user
27
+ @@backing_storage.write(user_name.to_s, user, :expires_in => BACKING_CACHE_EXPIRATION.minutes)
24
28
  end
25
29
 
26
30
  def invalidate(user_name)
27
- @cache ||= {}
28
- @cache[user_name.to_s] = nil
31
+ @@backing_storage.delete(user_name.to_s)
29
32
  end
30
33
 
31
- private
32
- def hit?(user_name)
33
- key = user_name.to_s
34
- @cache.key?(key) && !@cache[key].nil?
35
- end
36
34
  end
37
35
  end
38
36
  end
@@ -218,7 +218,7 @@ module Reactor
218
218
 
219
219
  def granted?(user, permission)
220
220
  user ||= default_user
221
- cache.lookup(user, "#{obj.path}:#{permission}") do
221
+ cache.lookup(user, "#{obj.id}:#{permission}") do
222
222
  lookup.superuser?(user) || lookup.send("#{permission}?", user)
223
223
  end
224
224
  end
@@ -13,6 +13,10 @@ module Reactor
13
13
  @superuser= user.is_root?
14
14
  end
15
15
 
16
+ def to_s
17
+ @user_name
18
+ end
19
+
16
20
  attr_reader :user_name, :groups, :language
17
21
 
18
22
  def superuser?
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Reactor
3
- VERSION = "1.15.0.beta1"
3
+ VERSION = "1.16.0"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infopark_reactor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.15.0.beta1
4
+ version: 1.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomasz Przedmojski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-25 00:00:00.000000000 Z
11
+ date: 2015-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -225,9 +225,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
225
225
  version: '0'
226
226
  required_rubygems_version: !ruby/object:Gem::Requirement
227
227
  requirements:
228
- - - '>'
228
+ - - '>='
229
229
  - !ruby/object:Gem::Version
230
- version: 1.3.1
230
+ version: '0'
231
231
  requirements: []
232
232
  rubyforge_project:
233
233
  rubygems_version: 2.0.14