public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Add method punctuation handling to #synchronize
Nick (author)
Sat Apr 19 08:18:02 -0700 2008
commit  9dc4f6611043d032e576d93430cd29efc8864bc4
tree    69473e5bbc8a4059a94c55ddac4eacb45180c1ca
parent  3eb68248e0c0495c4533792260c9262fcd2840af
...
19
20
21
22
 
 
 
23
24
25
26
 
27
28
 
29
30
31
...
19
20
21
 
22
23
24
25
26
27
 
28
29
 
30
31
32
33
0
@@ -19,13 +19,15 @@ class Module
0
     end
0
 
0
     methods.each do |method|
0
-      if instance_methods.include?("#{method}_without_synchronization")
0
+      aliased_method, punctuation = method.to_s.sub(/([?!=])$/, ''), $1
0
+      
0
+      if instance_methods.include?("#{aliased_method}_without_synchronization#{punctuation}")
0
         raise ArgumentError, "#{method} is already synchronized. Double synchronization is not currently supported."
0
       end
0
       module_eval(<<-EOS, __FILE__, __LINE__)
0
-        def #{method}_with_synchronization(*args, &block)
0
+        def #{aliased_method}_with_synchronization#{punctuation}(*args, &block)
0
           #{with}.synchronize do
0
-            #{method}_without_synchronization(*args,&block)
0
+            #{aliased_method}_without_synchronization#{punctuation}(*args,&block)
0
           end
0
         end
0
       EOS
...
54
55
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
58
...
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
0
@@ -54,4 +54,18 @@ class SynchronizationTest < Test::Unit::TestCase
0
     @instance.to_s
0
     assert_equal 2, dummy.sync_count
0
   end
0
+
0
+  def test_can_synchronize_method_with_punctuation
0
+    @target.module_eval do
0
+      def dangerous?
0
+        @dangerous
0
+      end
0
+      def dangerous!
0
+        @dangerous = true
0
+      end
0
+    end
0
+    @target.synchronize :dangerous?, :dangerous!, :with => :mutex
0
+    @instance.dangerous!
0
+    assert @instance.dangerous?
0
+  end
0
 end
0
\ No newline at end of file

Comments