lock_method 0.5.4 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ 0.5.5 / 2012-05-09
2
+
3
+ * Enhancements
4
+
5
+ * Provide a more helpful exception message that names the locked method
6
+ * A singleton doesn't need its own single-use mutex - just use Thread.exclusive
7
+
1
8
  0.5.4 / 2012-04-18
2
9
 
3
10
  * Enhancements
@@ -16,10 +16,8 @@ module LockMethod
16
16
  class Locked < ::StandardError
17
17
  end
18
18
 
19
- CONFIG_MUTEX = ::Mutex.new
20
-
21
19
  def LockMethod.config #:nodoc:
22
- @config || CONFIG_MUTEX.synchronize do
20
+ @config || ::Thread.exclusive do
23
21
  @config ||= Config.new
24
22
  end
25
23
  end
@@ -49,7 +49,7 @@ module LockMethod
49
49
  ::Kernel.sleep 0.5
50
50
  end
51
51
  if locked?
52
- raise Locked
52
+ raise Locked, %{#{method_signature} is currently locked.}
53
53
  else
54
54
  begin
55
55
  save
@@ -1,3 +1,3 @@
1
1
  module LockMethod
2
- VERSION = "0.5.4"
2
+ VERSION = "0.5.5"
3
3
  end
@@ -228,4 +228,20 @@ module SharedTests
228
228
  BlogBlock.get_latest_entries { $stderr.write "i'm now allowed" }
229
229
  end
230
230
  end
231
+
232
+ def test_016_gives_clear_exception_message
233
+ blocker = Thread.new { Blog2.get_latest_entries }
234
+
235
+ # give it a bit of time to lock
236
+ sleep 1
237
+
238
+ # the blocker won't have finished
239
+ exception = assert_raises(LockMethod::Locked) do
240
+ Blog2.get_latest_entries
241
+ end
242
+ assert_match /get_latest_entries/, exception.message
243
+
244
+ # wait to finish
245
+ blocker.join
246
+ end
231
247
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lock_method
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-18 00:00:00.000000000 Z
12
+ date: 2012-05-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cache