synchronizable 0.0.2 → 0.0.3

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.
@@ -13,10 +13,14 @@ module Synchronizable
13
13
 
14
14
  # redefine all user-defined methods to utilize lock
15
15
  obj.methods.each do |m|
16
- next if IGNORABLE_METHOD_OWNERS.include?(obj.method(m).owner)
16
+ original_method = obj.method(m)
17
+ next if IGNORABLE_METHOD_OWNERS.include?(original_method.owner)
18
+
19
+ without_sync_method = "#{original_method.name}_without_sync"
20
+ obj.define_singleton_method(without_sync_method, original_method)
17
21
  obj.define_singleton_method(m) do |*args, &block|
18
22
  __lock.synchronize do
19
- super(*args, &block)
23
+ send(without_sync_method, *args, &block)
20
24
  end
21
25
  end
22
26
  end
@@ -1,3 +1,3 @@
1
1
  module Synchronizable
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,7 +1,23 @@
1
1
  require 'spec_helper'
2
2
 
3
+ class TestLock
4
+ attr_reader :sync_invoked
5
+
6
+ def initialize
7
+ @sync_invoked = false
8
+ end
9
+
10
+ def synchronize(&block)
11
+ @sync_invoked = true
12
+ end
13
+
14
+ def reset
15
+ @sync_invoked = false
16
+ end
17
+ end
18
+
3
19
  describe Synchronizable do
4
- context "when extended by an object" do
20
+ context "when extended" do
5
21
  let(:object) { String.new }
6
22
 
7
23
  it "creates an instance-level lock" do
@@ -11,18 +27,6 @@ describe Synchronizable do
11
27
  end
12
28
 
13
29
  it "creates a locked version of each original method" do
14
- class TestLock
15
- attr_reader :sync_invoked
16
-
17
- def initialize
18
- @sync_invoked = false
19
- end
20
-
21
- def synchronize(&block)
22
- @sync_invoked = true
23
- end
24
- end
25
-
26
30
  lock = TestLock.new
27
31
  object.extend(Synchronizable)
28
32
  object.instance_variable_set(:@__lock, lock)
@@ -51,15 +55,33 @@ describe Synchronizable do
51
55
  t.extend(Synchronizable)
52
56
  t.m2.should == 10
53
57
  end
54
- end
55
58
 
56
- it "protects a block via #synchronize" do
57
- s = ""
58
- s.methods.should_not include(:synchronize)
59
- s.extend(Synchronizable)
60
- s.methods.should include(:synchronize)
61
- s.synchronize do
62
- s.split
59
+ it "handles singleton methods" do
60
+ class Foo
61
+ def self.m1
62
+ 100
63
+ end
64
+ end
65
+
66
+
67
+ Foo.m1.should == 100
68
+ lock = TestLock.new
69
+ Foo.extend(Synchronizable)
70
+ Foo.instance_variable_set(:@__lock, lock)
71
+
72
+ lock.sync_invoked.should == false
73
+ Foo.m1
74
+ lock.sync_invoked.should == true
75
+ end
76
+
77
+ it "protects a block via #synchronize" do
78
+ s = ""
79
+ s.methods.should_not include(:synchronize)
80
+ s.extend(Synchronizable)
81
+ s.methods.should include(:synchronize)
82
+ s.synchronize do
83
+ s.split
84
+ end
63
85
  end
64
86
  end
65
- end
87
+ end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synchronizable
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 2
9
- version: 0.0.2
4
+ prerelease:
5
+ version: 0.0.3
10
6
  platform: ruby
11
7
  authors:
12
8
  - Ryan LeCompte
@@ -14,8 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-07-29 00:00:00 -04:00
18
- default_executable:
13
+ date: 2011-08-04 00:00:00 Z
19
14
  dependencies:
20
15
  - !ruby/object:Gem::Dependency
21
16
  name: rspec
@@ -25,10 +20,6 @@ dependencies:
25
20
  requirements:
26
21
  - - ~>
27
22
  - !ruby/object:Gem::Version
28
- segments:
29
- - 2
30
- - 5
31
- - 0
32
23
  version: 2.5.0
33
24
  type: :development
34
25
  version_requirements: *id001
@@ -52,7 +43,6 @@ files:
52
43
  - spec/spec_helper.rb
53
44
  - spec/synchronizable/synchronizable_spec.rb
54
45
  - synchronizable.gemspec
55
- has_rdoc: true
56
46
  homepage: http://github.com/ryanlecompte/synchronizable
57
47
  licenses: []
58
48
 
@@ -66,21 +56,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
66
56
  requirements:
67
57
  - - ">="
68
58
  - !ruby/object:Gem::Version
69
- segments:
70
- - 0
71
59
  version: "0"
72
60
  required_rubygems_version: !ruby/object:Gem::Requirement
73
61
  none: false
74
62
  requirements:
75
63
  - - ">="
76
64
  - !ruby/object:Gem::Version
77
- segments:
78
- - 0
79
65
  version: "0"
80
66
  requirements: []
81
67
 
82
68
  rubyforge_project: synchronizable
83
- rubygems_version: 1.3.7
69
+ rubygems_version: 1.8.6
84
70
  signing_key:
85
71
  specification_version: 3
86
72
  summary: Synchronizable is a generic way to provide per-object thread safety