Class: Class

Inherits:
Object show all
Defined in:
lib/mongo/util/core_ext.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#mongo_thread_local_accessor(name, options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/mongo/util/core_ext.rb', line 46

def mongo_thread_local_accessor name, options = {}
  m = Module.new
  m.module_eval do
    class_variable_set :"@@#{name}", Hash.new {|h,k| h[k] = options[:default] }
  end
  m.module_eval %{

    def #{name}
      @@#{name}[Thread.current.object_id]
    end

    def #{name}=(val)
      @@#{name}[Thread.current.object_id] = val
    end
  }

  class_eval do
    include m
    extend m
  end
end