class Cased::Context

Attributes

context[R]

Public Class Methods

clear!() click to toggle source
# File lib/cased/context.rb, line 16
def self.clear!
  Thread.current[:cased_context] = nil
end
current() click to toggle source
# File lib/cased/context.rb, line 8
def self.current
  Thread.current[:cased_context] ||= new
end
current=(context) click to toggle source
# File lib/cased/context.rb, line 12
def self.current=(context)
  Thread.current[:cased_context] = new(context)
end
new(context = {}) click to toggle source
# File lib/cased/context.rb, line 22
def initialize(context = {})
  @context = Cased::Context::Expander.expand(context || {})
end

Public Instance Methods

[](key) click to toggle source
# File lib/cased/context.rb, line 42
def [](key)
  @context[key]
end
[]=(key, value) click to toggle source
# File lib/cased/context.rb, line 46
def []=(key, value)
  merge(key => value)
end
clear() click to toggle source
# File lib/cased/context.rb, line 26
def clear
  @context = {}
end
merge(new_context = {}) { || ... } click to toggle source
# File lib/cased/context.rb, line 30
def merge(new_context = {})
  if block_given?
    old_context = @context.dup
    @context.deep_merge!(Cased::Context::Expander.expand(new_context))
    yield
  else
    @context.deep_merge!(Cased::Context::Expander.expand(new_context))
  end
ensure
  @context = old_context if block_given?
end