barney 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/ChangeLog CHANGED
@@ -1,10 +1,15 @@
1
+ 2011-02-16 Robert Gleeson <rob@flowof.info> v0.4.1
2
+
3
+ * Add http://www.gem-testers.org support.
4
+ * Rewrite test suite using 'minitest'.
5
+
1
6
  2011-02-12 Robert Gleeson <rob@flowof.info> v0.4.0
2
7
 
3
8
  * Add Barney::Share#history.
4
9
 
5
10
  2011-01-16 Robert Gleeson <rob@flowof.info> v0.3.1
6
11
 
7
- * Bug Fix(See GH-Issue 1)
12
+ * Solve Github Issue #1.
8
13
  * Add Barney::Share#pid.
9
14
 
10
15
  2011-01-04 Robert Gleeson <rob@flowof.info> v0.2.0
data/README.md CHANGED
@@ -51,8 +51,8 @@ Okay, now that we've got that out of the way, let's see what using Barney is lik
51
51
 
52
52
  3.upto(4).each do |i|
53
53
  pid = obj.fork { a << i.to_s }
54
- obj.sync
55
54
  Process.wait pid
55
+ obj.sync
56
56
  end
57
57
 
58
58
  a # => "1234"
@@ -74,7 +74,7 @@ Okay, now that we've got that out of the way, let's see what using Barney is lik
74
74
  end
75
75
  end
76
76
 
77
- pids.each { |pid| Process.wait(pid) }
77
+ pids.each { |pid| Process.wait pid }
78
78
  obj.sync
79
79
 
80
80
  obj.history.each_value do |history|
@@ -88,6 +88,7 @@ Okay, now that we've got that out of the way, let's see what using Barney is lik
88
88
  **API**
89
89
 
90
90
  * [master (git)](http://rubydoc.info/github/robgleeson/Barney/master/)
91
+ * [0.4.1](http://rubydoc.info/gems/barney/0.4.1)
91
92
  * [0.4.0](http://rubydoc.info/gems/barney/0.4.0)
92
93
  * [0.3.1](http://rubydoc.info/gems/barney/0.3.1)
93
94
  * [0.2.0](http://rubydoc.info/gems/barney/0.2.0)
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ task :test do
2
+ $LOAD_PATH.unshift './lib'
3
+ require 'barney'
4
+ require 'minitest/spec'
5
+ require 'minitest/autorun'
6
+ Dir.glob("test/suite/lib/**/*.rb").each { |test| require_relative test }
7
+ end
data/lib/barney/share.rb CHANGED
@@ -97,7 +97,7 @@ module Barney
97
97
  Barney::Share.value = Marshal.load hash[seq][0].read
98
98
  hash[seq][0].close
99
99
  object = eval "#{variable} = Barney::Share.value", @context
100
- @history.merge!({ seq => { variable => object } })
100
+ @history[seq] = { variable => object }
101
101
  end
102
102
  end
103
103
  end
data/lib/barney.rb CHANGED
@@ -2,7 +2,7 @@ require('barney/share')
2
2
 
3
3
  module Barney
4
4
 
5
- VERSION = '0.4.0'
5
+ VERSION = '0.4.1'
6
6
 
7
7
  end
8
8
 
@@ -0,0 +1,18 @@
1
+ describe Barney::Share do
2
+ describe '#fork' do
3
+
4
+ it 'should return the Process ID(PID) is on success.' do
5
+ pid = Barney::Share.new.fork { }
6
+ Process.wait pid
7
+ assert_equal Fixnum, pid.class
8
+ end
9
+
10
+ it 'should raise an ArgumentError without a block or Proc.' do
11
+ assert_raises ArgumentError do
12
+ Barney::Share.new.fork
13
+ end
14
+ end
15
+
16
+ end
17
+ end
18
+
@@ -0,0 +1,20 @@
1
+ describe Barney::Share do
2
+ describe '#history' do
3
+
4
+ it 'should confirm #history provides the correct history' do
5
+ hash = {}
6
+ expected = { 0 => { :hash => { 1 => 1 } }, 1 => { :hash => { 2 => 2 } }, 2 => { :hash => { 3 => 3 } } }
7
+ object = Barney::Share.new
8
+ object.share :hash
9
+
10
+ [1,2,3].each do |e|
11
+ pid = object.fork { hash.merge! e => e }
12
+ Process.wait pid
13
+ end
14
+
15
+ object.sync
16
+ assert_equal expected, object.history
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,11 @@
1
+ describe Barney::Share do
2
+ describe '#shared' do
3
+
4
+ it 'should return a list of shared variables' do
5
+ obj = Barney::Share.new
6
+ obj.share :a, :b, :c
7
+ assert_equal true, [:a, :b, :c].all? { |variable| obj.shared.include? variable }
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,55 @@
1
+ describe Barney::Share do
2
+ describe '#sync' do
3
+
4
+ before do
5
+ @object = Barney::Share.new
6
+ end
7
+
8
+ it 'should confirm a variable can be synced.' do
9
+ a = 5
10
+ @object.share :a
11
+ pid = @object.fork { a = 6 }
12
+ Process.wait pid
13
+ @object.sync
14
+ assert_equal 6, a
15
+ end
16
+
17
+ it 'should confirm a variable can be synced after mutation' do
18
+ a = 'abc'
19
+ @object.share :a
20
+ pid = @object.fork { a.sub! 'a','b' }
21
+ Process.wait pid
22
+ @object.sync
23
+ assert_equal 'bbc', a
24
+ end
25
+
26
+ it 'should confirm two variables can be synced.' do
27
+ a,b = 10,20
28
+ @object.share :a,:b
29
+ pid = @object.fork { a,b = 4,5 }
30
+ Process.wait pid
31
+ @object.sync
32
+
33
+ assert_equal 4, a
34
+ assert_equal 5, b
35
+ end
36
+
37
+ it 'should fix Github Issue #1' do
38
+ $times = 2
39
+ @object.share :$times
40
+
41
+ pid = @object.fork { $times = 4 }
42
+ pid2 = @object.fork { $times = 5 }
43
+ pid3 = @object.fork { $times = 6 }
44
+
45
+ Process.wait pid
46
+ Process.wait pid2
47
+ Process.wait pid3
48
+ @object.sync
49
+
50
+ assert_equal 6, $times
51
+ end
52
+
53
+ end
54
+ end
55
+
@@ -0,0 +1,27 @@
1
+ describe Barney::Share do
2
+ describe '#unshare' do
3
+
4
+ before do
5
+ @a = 5
6
+ @object = Barney::Share.new
7
+ end
8
+
9
+ it 'should confirm a variable can be unshared before a subprocess is spawned.' do
10
+ @object.share :@a
11
+ @object.unshare :@a
12
+ pid = @object.fork { @a = 6 }
13
+ Process.wait pid
14
+ @object.sync
15
+
16
+ assert_equal 5, @a
17
+ end
18
+
19
+ it 'should confirm a shared variable is removed from #shared.' do
20
+ @object.share :@a
21
+ @object.unshare :@a
22
+ assert_equal true, @object.shared.empty?
23
+ end
24
+
25
+ end
26
+ end
27
+
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barney
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 4
9
- - 0
10
- version: 0.4.0
8
+ - 1
9
+ version: 0.4.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - Robert Gleeson
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-02-13 00:00:00 +00:00
17
+ date: 2011-02-16 00:00:00 +00:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 3
30
28
  segments:
31
29
  - 0
32
30
  version: "0"
@@ -40,26 +38,11 @@ dependencies:
40
38
  requirements:
41
39
  - - ">="
42
40
  - !ruby/object:Gem::Version
43
- hash: 3
44
41
  segments:
45
42
  - 0
46
43
  version: "0"
47
44
  type: :development
48
45
  version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: riot
51
- prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
53
- none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
- version: "0"
61
- type: :development
62
- version_requirements: *id003
63
46
  description: Barney tries to make the sharing of data between processes as easy and natural as possible.
64
47
  email: rob@flowof.info
65
48
  executables: []
@@ -69,12 +52,19 @@ extensions: []
69
52
  extra_rdoc_files: []
70
53
 
71
54
  files:
55
+ - Rakefile
72
56
  - LICENSE
73
57
  - .yardopts
74
58
  - README.md
75
59
  - ChangeLog
60
+ - .gemtest
76
61
  - lib/barney/share.rb
77
62
  - lib/barney.rb
63
+ - test/suite/lib/barney/share#fork.rb
64
+ - test/suite/lib/barney/share#history.rb
65
+ - test/suite/lib/barney/share#shared.rb
66
+ - test/suite/lib/barney/share#synchronize.rb
67
+ - test/suite/lib/barney/share#unshare.rb
78
68
  has_rdoc: true
79
69
  homepage: http://github.com/robgleeson/barney
80
70
  licenses: []
@@ -89,7 +79,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
79
  requirements:
90
80
  - - ">="
91
81
  - !ruby/object:Gem::Version
92
- hash: 49
93
82
  segments:
94
83
  - 1
95
84
  - 9
@@ -100,7 +89,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
89
  requirements:
101
90
  - - ">="
102
91
  - !ruby/object:Gem::Version
103
- hash: 23
104
92
  segments:
105
93
  - 1
106
94
  - 3
@@ -113,5 +101,9 @@ rubygems_version: 1.3.7
113
101
  signing_key:
114
102
  specification_version: 3
115
103
  summary: Barney tries to make the sharing of data between processes as easy and natural as possible.
116
- test_files: []
117
-
104
+ test_files:
105
+ - test/suite/lib/barney/share#fork.rb
106
+ - test/suite/lib/barney/share#history.rb
107
+ - test/suite/lib/barney/share#shared.rb
108
+ - test/suite/lib/barney/share#synchronize.rb
109
+ - test/suite/lib/barney/share#unshare.rb