@@ -9,13 +9,17 @@ module Concern
9
9
#
10
10
# @!macro copy_options
11
11
module Dereferenceable
12
+ # NOTE: This module is going away in 2.0. In the mean time we need it to
13
+ # play nicely with the synchronization layer. This means that the
14
+ # including class SHOULD be synchronized and it MUST implement a
15
+ # `#synchronize` method. Not doing so will lead to runtime errors.
12
16
13
17
# Return the value this object represents after applying the options specified
14
18
# by the `#set_deref_options` method.
15
19
#
16
20
# @return [Object] the current value of the object
17
21
def value
18
- mutex . synchronize { apply_deref_options ( @value ) }
22
+ synchronize { apply_deref_options ( @value ) }
19
23
end
20
24
alias_method :deref , :value
21
25
@@ -25,43 +29,24 @@ def value
25
29
#
26
30
# @param [Object] value the new value
27
31
def value = ( value )
28
- mutex . synchronize { @value = value }
29
- end
30
-
31
- # A mutex lock used for synchronizing thread-safe operations. Methods defined
32
- # by `Dereferenceable` are synchronized using the `Mutex` returned from this
33
- # method. Operations performed by the including class that operate on the
34
- # `@value` instance variable should be locked with this `Mutex`.
35
- #
36
- # @return [Mutex] the synchronization object
37
- def mutex
38
- @mutex
39
- end
40
-
41
- # Initializes the internal `Mutex`.
42
- #
43
- # @note This method *must* be called from within the constructor of the including class.
44
- #
45
- # @see #mutex
46
- def init_mutex ( mutex = Mutex . new )
47
- @mutex = mutex
32
+ synchronize { @value = value }
48
33
end
49
34
50
35
# @!macro [attach] dereferenceable_set_deref_options
51
36
# Set the options which define the operations #value performs before
52
37
# returning data to the caller (dereferencing).
53
- #
38
+ #
54
39
# @note Most classes that include this module will call `#set_deref_options`
55
40
# from within the constructor, thus allowing these options to be set at
56
41
# object creation.
57
- #
42
+ #
58
43
# @param [Hash] opts the options defining dereference behavior.
59
44
# @option opts [String] :dup_on_deref (false) call `#dup` before returning the data
60
45
# @option opts [String] :freeze_on_deref (false) call `#freeze` before returning the data
61
46
# @option opts [String] :copy_on_deref (nil) call the given `Proc` passing
62
47
# the internal value and returning the value returned from the proc
63
48
def set_deref_options ( opts = { } )
64
- mutex . synchronize { ns_set_deref_options ( opts ) }
49
+ synchronize { ns_set_deref_options ( opts ) }
65
50
end
66
51
67
52
# @!macro dereferenceable_set_deref_options
0 commit comments