Class: Global
- Inherits:
-
Object
- Object
- Global
- Defined in:
- lib/raw/context/global.rb
Overview
Global scoped variables. This is backed by a Cache store. – TODO: implement as a refactoring of session? ++
Class Attribute Summary collapse
-
.cache ⇒ Object
The global cache (store).
Class Method Summary collapse
- .delete(key) ⇒ Object
- .get(key) ⇒ Object (also: [])
-
.init(key, value) ⇒ Object
Initialize a global value once.
- .set(key, value) ⇒ Object (also: []=)
-
.setup(type = Global.cache_type) ⇒ Object
Init the correct Global cache.
-
.update(key) ⇒ Object
If block is given it acts as an update methods, that transparently handles distributed stores.
Class Attribute Details
.cache ⇒ Object
The global cache (store).
30 31 32 |
# File 'lib/raw/context/global.rb', line 30 def cache @cache end |
Class Method Details
.delete(key) ⇒ Object
82 83 84 |
# File 'lib/raw/context/global.rb', line 82 def delete(key) Global.cache.delete(key) end |
.get(key) ⇒ Object Also known as: []
61 62 63 |
# File 'lib/raw/context/global.rb', line 61 def get(key) return Global.cache[key] end |
.init(key, value) ⇒ Object
Initialize a global value once.
50 51 52 53 54 |
# File 'lib/raw/context/global.rb', line 50 def init(key, value) unless Global[key] Global[key] = value end end |
.set(key, value) ⇒ Object Also known as: []=
56 57 58 |
# File 'lib/raw/context/global.rb', line 56 def set(key, value) Global.cache[key] = value end |
.setup(type = Global.cache_type) ⇒ Object
Init the correct Global cache.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/raw/context/global.rb', line 34 def setup(type = Global.cache_type) return if Global.cache case type when :memory require 'glue/cache/memory' Global.cache = Glue::MemoryCache.new when :drb require 'glue/cache/drb' Global.cache = DrbCache.new(Global.cache_address, Global.cache_port) end end |
.update(key) ⇒ Object
If block is given it acts as an update methods, that transparently handles distributed stores.
Global.update(:USERS) do |users|
users << 'gmosx'
end
73 74 75 76 77 78 79 80 |
# File 'lib/raw/context/global.rb', line 73 def update(key) if block_given? # update, also handles distributed stores. val = Global.cache[key] yield val Global.cache[key] = val end end |