67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/zeevex_threadsafe/thread_locals.rb', line 67
def self.define_thread_local_accessors(base, args, block = nil)
options = args[-1].instance_of?(Hash) ? args.pop : {}
args.each do |name|
key = name.to_sym
base.class_eval do
define_method name.to_sym do
hash = ZeevexThreadsafe::ThreadLocals::UtilityMethods.thread_local_hash(self)
return hash[key] if hash && hash.key?(key)
return block.call(self, key) if block
return options[:default]
end
define_method (name.to_s + "=").to_sym do |value|
ZeevexThreadsafe::ThreadLocals::UtilityMethods.thread_local_hash(self, true)[key] = value
end
if options[:visibility]
send options[:visibility], name.to_sym, (name.to_s + "=").to_sym
end
end
end
end
|