Class: BBServer::ContextLocals

Inherits:
Object
  • Object
show all
Defined in:
lib/bbserver/context_locals.rb

Instance Method Summary collapse

Constructor Details

#initializeContextLocals

Returns a new instance of ContextLocals.



5
6
7
# File 'lib/bbserver/context_locals.rb', line 5

def initialize
  @storage = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/bbserver/context_locals.rb', line 17

def method_missing(name, *args, &block)
  if name.to_s.end_with?('=')
    set(name.to_s.chomp('='), args.first)
  elsif @storage.key?(name.to_sym)
    get(name)
  else
    super
  end
end

Instance Method Details

#get(key) ⇒ Object



9
10
11
# File 'lib/bbserver/context_locals.rb', line 9

def get(key)
  @storage[key.to_sym]
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/bbserver/context_locals.rb', line 27

def respond_to_missing?(name, include_private = false)
  @storage.key?(name.to_s.chomp('=').to_sym) || super
end

#set(key, value) ⇒ Object



13
14
15
# File 'lib/bbserver/context_locals.rb', line 13

def set(key, value)
  @storage[key.to_sym] = value
end