Class: ActiveContext::Context
- Inherits:
-
Object
- Object
- ActiveContext::Context
- Defined in:
- lib/activecontext/context.rb
Instance Attribute Summary collapse
-
#deserialize ⇒ Object
Returns the value of attribute deserialize.
-
#serialize ⇒ Object
Returns the value of attribute serialize.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(storage) ⇒ Context
constructor
A new instance of Context.
Constructor Details
#initialize(storage) ⇒ Context
Returns a new instance of Context.
4 5 6 7 8 9 |
# File 'lib/activecontext/context.rb', line 4 def initialize(storage) @storage = storage @values = {} @serialize = ->(key, value){ value } @deserialize = ->(key, value){ value } end |
Instance Attribute Details
#deserialize ⇒ Object
Returns the value of attribute deserialize.
3 4 5 |
# File 'lib/activecontext/context.rb', line 3 def deserialize @deserialize end |
#serialize ⇒ Object
Returns the value of attribute serialize.
3 4 5 |
# File 'lib/activecontext/context.rb', line 3 def serialize @serialize end |
Instance Method Details
#[](key) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/activecontext/context.rb', line 10 def [](key) if @values.key?(key) @values[key] else @values[key] = @deserialize.call(key, @storage[key]) end end |
#[]=(key, value) ⇒ Object
17 18 19 20 |
# File 'lib/activecontext/context.rb', line 17 def []=(key, value) @storage[key] = @serialize.call(key, value) @values[key] = value end |