Class: FrozenRecord::Base::ThreadSafeStorage
- Inherits:
-
Object
- Object
- FrozenRecord::Base::ThreadSafeStorage
- Defined in:
- lib/frozen_record/base.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(key) ⇒ ThreadSafeStorage
constructor
A new instance of ThreadSafeStorage.
Constructor Details
#initialize(key) ⇒ ThreadSafeStorage
Returns a new instance of ThreadSafeStorage.
42 43 44 |
# File 'lib/frozen_record/base.rb', line 42 def initialize(key) @thread_key = "#{ self.object_id }-#{ key }" end |
Instance Method Details
#[](key) ⇒ Object
46 47 48 49 |
# File 'lib/frozen_record/base.rb', line 46 def [](key) Thread.current[@thread_key] ||= {} Thread.current[@thread_key][key] end |
#[]=(key, value) ⇒ Object
51 52 53 54 |
# File 'lib/frozen_record/base.rb', line 51 def []=(key, value) Thread.current[@thread_key] ||= {} Thread.current[@thread_key][key] = value end |