Class: Cased::Context
- Inherits:
-
Object
- Object
- Cased::Context
- Defined in:
- lib/cased/context.rb,
lib/cased/context/expander.rb
Defined Under Namespace
Classes: Expander
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #clear ⇒ Object
-
#initialize(context = {}) ⇒ Context
constructor
A new instance of Context.
- #merge(new_context = {}) ⇒ Object
Constructor Details
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
20 21 22 |
# File 'lib/cased/context.rb', line 20 def context @context end |
Class Method Details
.clear! ⇒ Object
16 17 18 |
# File 'lib/cased/context.rb', line 16 def self.clear! Thread.current[:cased_context] = nil end |
.current ⇒ Object
8 9 10 |
# File 'lib/cased/context.rb', line 8 def self.current Thread.current[:cased_context] ||= new end |
.current=(context) ⇒ Object
12 13 14 |
# File 'lib/cased/context.rb', line 12 def self.current=(context) Thread.current[:cased_context] = new(context) end |
Instance Method Details
#[](key) ⇒ Object
42 43 44 |
# File 'lib/cased/context.rb', line 42 def [](key) @context[key] end |
#[]=(key, value) ⇒ Object
46 47 48 |
# File 'lib/cased/context.rb', line 46 def []=(key, value) merge(key => value) end |
#clear ⇒ Object
26 27 28 |
# File 'lib/cased/context.rb', line 26 def clear @context = {} end |
#merge(new_context = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cased/context.rb', line 30 def merge(new_context = {}) if block_given? old_context = @context.dup @context.deep_merge!(Cased::Context::Expander.(new_context)) yield else @context.deep_merge!(Cased::Context::Expander.(new_context)) end ensure @context = old_context if block_given? end |