Class: VCAP::Component::SafeHash
- Inherits:
-
BasicObject
- Defined in:
- lib/vcap/component.rb
Instance Method Summary
collapse
Constructor Details
#initialize(hash = {}) ⇒ SafeHash
Returns a new instance of SafeHash.
49
50
51
|
# File 'lib/vcap/component.rb', line 49
def initialize(hash = {})
@hash = hash
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &blk) ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/vcap/component.rb', line 76
def method_missing(sym, *args, &blk)
if @monitor && @thread != ::Thread.current
::Kernel.raise "Lock required"
end
@hash.__send__(sym, *args, &blk)
end
|
Instance Method Details
#class ⇒ Object
53
54
55
|
# File 'lib/vcap/component.rb', line 53
def class
SafeHash
end
|
#synchronize ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/vcap/component.rb', line 61
def synchronize
if @monitor
@monitor.synchronize do
begin
@thread = ::Thread.current
yield
ensure
@thread = nil
end
end
else
yield
end
end
|
#threadsafe! ⇒ Object
57
58
59
|
# File 'lib/vcap/component.rb', line 57
def threadsafe!
@monitor = ::Monitor.new
end
|