Wrap config's data hash in mutex

This commit is contained in:
Łukasz Strzałkowski 2013-10-21 20:15:06 +00:00
parent 55baaf2005
commit d46584af40

View File

@ -1,27 +1,39 @@
require 'thread'
module ActiveModel
class Serializer
class Config
def initialize
@data = {}
@mutex = Mutex.new
end
def [](key)
@mutex.synchronize do
@data[key.to_s]
end
end
def []=(key, value)
@mutex.synchronize do
@data[key.to_s] = value
end
end
def each(&block)
@mutex.synchronize do
@data.each(&block)
end
end
def clear
@mutex.synchronize do
@data.clear
end
end
def method_missing(name, *args)
@mutex.synchronize do
name = name.to_s
return @data[name] if @data.include?(name)
match = name.match(/\A(.*?)([?=]?)\Z/)
@ -33,6 +45,7 @@ module ActiveModel
end
end
end
end
CONFIG = Config.new
end