Class: Yaoc::Helper::ThreadLocalStorage

Inherits:
Object
  • Object
show all
Defined in:
lib/yaoc/helper/thread_local_storage.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeThreadLocalStorage

Returns a new instance of ThreadLocalStorage.



14
15
16
# File 'lib/yaoc/helper/thread_local_storage.rb', line 14

def initialize
  self.data||={}
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



8
9
10
# File 'lib/yaoc/helper/thread_local_storage.rb', line 8

def data
  @data
end

Class Method Details

.for(scope_name = "default") ⇒ Object



10
11
12
# File 'lib/yaoc/helper/thread_local_storage.rb', line 10

def self.for(scope_name="default")
  Thread.current["_#{name}_#{scope_name}"] ||= new
end

Instance Method Details

#[](key) ⇒ Object



22
23
24
# File 'lib/yaoc/helper/thread_local_storage.rb', line 22

def [](key)
  self.data[key]
end

#[]=(key, value) ⇒ Object



18
19
20
# File 'lib/yaoc/helper/thread_local_storage.rb', line 18

def []=(key, value)
  self.data[key]=value
end

#clear!Object



26
27
28
# File 'lib/yaoc/helper/thread_local_storage.rb', line 26

def clear!
  self.data.clear
end

#fetch(*args, &block) ⇒ Object



30
31
32
# File 'lib/yaoc/helper/thread_local_storage.rb', line 30

def fetch(*args, &block)
  self.data.fetch(*args, &block)
end