Class: Yaoc::Helper::ThreadLocalStorage
- Inherits:
-
Object
- Object
- Yaoc::Helper::ThreadLocalStorage
- Defined in:
- lib/yaoc/helper/thread_local_storage.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #clear! ⇒ Object
- #fetch(*args, &block) ⇒ Object
-
#initialize ⇒ ThreadLocalStorage
constructor
A new instance of ThreadLocalStorage.
Constructor Details
#initialize ⇒ ThreadLocalStorage
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
#data ⇒ Object
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 |