barney 0.8.0 → 0.8.1

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,8 @@
1
+ 2011-04-19 Robert Gleeson <rob@flowof.info> v0.8.1
2
+
3
+ * Don't call #to_sym when it isn't required.
4
+ * Don't allow @variables be populated with duplicates. (bugfix)
5
+
1
6
  2011-04-19 Robert Gleeson <rob@flowof.info> v0.8.0
2
7
 
3
8
  * Remove "seq" attribute from StreamPair.
data/README.md CHANGED
@@ -43,10 +43,12 @@ Okay, now that we've got that out of the way, let's see what using Barney is lik
43
43
 
44
44
  ## Install
45
45
 
46
- RubyGems.org
46
+ RubyGems.org
47
+
47
48
  gem install barney
48
49
 
49
- Github
50
+ Github
51
+
50
52
  git clone git://github.com/robgleeson/barney.git
51
53
  cd barney
52
54
  gem build *.gemspec
@@ -59,11 +61,13 @@ I'm following the [Semantic Versioning](http://www.semver.org) policy.
59
61
  **API**
60
62
 
61
63
  * [master (git)](http://rubydoc.info/github/robgleeson/Barney/master/)
64
+ * [0.8.1](http://rubydoc.info/gems/barney/0.8.1/)
65
+ * [0.8.0](http://rubydoc.info/gems/barney/0.8.0/)
62
66
  * [0.7.0](http://rubydoc.info/gems/barney/0.7.0)
63
67
  * [0.6.0](http://rubydoc.info/gems/barney/0.6.0)
64
68
  * [0.5.0](http://rubydoc.info/gems/barney/0.5.0)
65
69
  * [0.4.1](http://rubydoc.info/gems/barney/0.4.1)
66
- * [0.4.0](http://rubydoc.info/gems/barney/0.4.0)
70
+ * [0.4.0](http://rubydoc.info/gems/barney/0.4.0)
67
71
  * …
68
72
 
69
73
 
data/lib/barney/share.rb CHANGED
@@ -51,6 +51,7 @@ module Barney
51
51
  # @return [Array<Symbol>] Returns a list of all variables that are being shared.
52
52
  def share *variables
53
53
  @variables.push *variables.map(&:to_sym)
54
+ @variables.uniq!
54
55
  end
55
56
 
56
57
  # Serves as a method to remove a variable or constant from being shared between two processes.
@@ -99,7 +100,7 @@ module Barney
99
100
  Barney::Share.value = Marshal.load stream.in.read
100
101
  stream.in.close
101
102
  value = eval "#{variable} = Barney::Share.value", @context
102
- @history.push HistoryItem.new variable.to_sym, value
103
+ @history.push HistoryItem.new variable, value
103
104
  end
104
105
  end
105
106
  end
data/lib/barney.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'barney/share'
2
2
 
3
3
  module Barney
4
- VERSION = '0.8.0'
4
+ VERSION = '0.8.1'
5
5
  end
6
6
 
@@ -1,4 +1,5 @@
1
1
  describe Barney::Share do
2
+
2
3
  describe '#fork' do
3
4
 
4
5
  it 'should return the Process ID(PID) on success.' do
@@ -14,5 +15,6 @@ describe Barney::Share do
14
15
  end
15
16
 
16
17
  end
18
+
17
19
  end
18
20
 
@@ -1,22 +1,24 @@
1
1
  describe Barney::Share do
2
+
2
3
  describe '#history' do
3
4
 
4
5
  it 'should provide the correct history.' do
5
6
  object = Barney::Share.new
6
- object.share :shared
7
- shared = ""
7
+ object.share :message
8
+ message = ""
8
9
 
9
- %w(a b c).each do |e|
10
- pid = object.fork { shared << e }
10
+ %w(a b c).each do |letter|
11
+ pid = object.fork { message << letter }
11
12
  Process.wait pid
12
13
  end
13
14
 
14
15
  object.sync
15
16
 
16
17
  history = object.history
17
- assert_equal true, history.all? { |item| item.variable == :shared }
18
+ assert_equal true, history.all? { |item| item.variable == :message }
18
19
  assert_equal "abc", history.map { |item| item.value }.join
19
20
  end
20
21
 
21
22
  end
23
+
22
24
  end
@@ -1,11 +1,17 @@
1
1
  describe Barney::Share do
2
+
2
3
  describe '#initialize' do
3
4
 
4
5
  it 'should take a block' do
5
- actual = false
6
- Barney::Share.new { |obj| actual = true }
7
- assert_equal true, actual
6
+ called = false
7
+
8
+ Barney::Share.new do |obj|
9
+ called = true
10
+ end
11
+
12
+ assert_equal true, called
8
13
  end
9
14
 
10
15
  end
16
+
11
17
  end
@@ -0,0 +1,19 @@
1
+ describe Barney::Share do
2
+
3
+ describe '#share' do
4
+
5
+ it "should assert duplicates aren't stored." do
6
+ instance = Barney::Share.new
7
+ instance.share :a, :a, :a, :a
8
+ instance.variables == [:a]
9
+ end
10
+
11
+ it "should assert variable names are stored as Symbols" do
12
+ instance = Barney::Share.new
13
+ instance.share "a", "b"
14
+ instance.variables == [:a, :b]
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -1,51 +1,63 @@
1
1
  describe Barney::Share do
2
+
2
3
  describe '#sync' do
3
4
 
4
5
  before do
5
- @object = Barney::Share.new
6
+ @instance = Barney::Share.new
6
7
  end
7
8
 
8
- it 'should confirm a variable can be synced.' do
9
- a = 5
10
- @object.share :a
11
- pid = @object.fork { a = 6 }
9
+ it 'should assert a variable can be synced.' do
10
+ x = 5
11
+
12
+ @instance.share :x
13
+ pid = @instance.fork do
14
+ x = 6
15
+ end
12
16
  Process.wait pid
13
- @object.sync
14
- assert_equal 6, a
17
+ @instance.sync
18
+
19
+ assert_equal 6, x
15
20
  end
16
21
 
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' }
22
+ it 'should assert a variable can be synced after mutation' do
23
+ message = 'foo'
24
+
25
+ @instance.share :message
26
+ pid = @instance.fork { message.sub! 'foo','bar' }
21
27
  Process.wait pid
22
- @object.sync
23
- assert_equal 'bbc', a
28
+ @instance.sync
29
+
30
+ assert_equal 'bar', message
24
31
  end
25
32
 
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 }
33
+ it 'should assert two variables can be synced.' do
34
+ x = 10
35
+ y = 20
36
+
37
+ @instance.share :x, :y
38
+ pid = @instance.fork do
39
+ x -= 1
40
+ y -= 1
41
+ end
30
42
  Process.wait pid
31
- @object.sync
43
+ @instance.sync
32
44
 
33
- assert_equal 4, a
34
- assert_equal 5, b
45
+ assert_equal 9 , x
46
+ assert_equal 19, y
35
47
  end
36
48
 
37
49
  it 'should fix Github Issue #1' do
38
50
  $times = 2
39
- @object.share :$times
51
+ @instance.share :$times
40
52
 
41
- pid = @object.fork { $times = 4 }
42
- pid2 = @object.fork { $times = 5 }
43
- pid3 = @object.fork { $times = 6 }
53
+ pid = @instance.fork { $times = 4 }
54
+ pid2 = @instance.fork { $times = 5 }
55
+ pid3 = @instance.fork { $times = 6 }
44
56
 
45
57
  Process.wait pid
46
58
  Process.wait pid2
47
59
  Process.wait pid3
48
- @object.sync
60
+ @instance.sync
49
61
 
50
62
  assert_equal 6, $times
51
63
  end
@@ -54,30 +66,31 @@ describe Barney::Share do
54
66
  x = 4
55
67
  y = 5
56
68
 
57
- @object.share :x
58
- @object.fork { }
59
- Process.wait @object.pid
69
+ @instance.share :x
70
+ @instance.fork { }
71
+ Process.wait @instance.pid
60
72
 
61
- @object.share :y
62
- @object.fork { b = 6 }
63
- Process.wait @object.pid
73
+ @instance.share :y
74
+ @instance.fork { b = 6 }
75
+ Process.wait @instance.pid
64
76
 
65
- @object.sync # will raise NoMethodError if fails.
77
+ @instance.sync # will raise NoMethodError if fails.
66
78
  end
67
79
 
68
80
  it 'should fix GitHub Issue #3' do
69
81
  x = 4
70
82
  y = 5
71
83
 
72
- @object.share :x, :y
73
- @object.fork { }
74
- Process.wait @object.pid
75
- @object.sync
84
+ @instance.share :x, :y
85
+ @instance.fork { }
86
+ Process.wait @instance.pid
87
+ @instance.sync
76
88
 
77
- assert_equal 4, @object.history[0].value
78
- assert_equal 5, @object.history[1].value
89
+ assert_equal 4, @instance.history[0].value
90
+ assert_equal 5, @instance.history[1].value
79
91
  end
80
92
 
81
93
  end
94
+
82
95
  end
83
96
 
@@ -1,27 +1,44 @@
1
1
  describe Barney::Share do
2
+
2
3
  describe '#unshare' do
3
4
 
4
5
  before do
5
- @a = 5
6
- @object = Barney::Share.new
6
+ @instance = Barney::Share.new
7
7
  end
8
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 }
9
+ it 'should assert a variable can be unshared before a subprocess is spawned.' do
10
+ x = 5
11
+
12
+ @instance.share :x
13
+ @instance.unshare :x
14
+ pid = @instance.fork do
15
+ x = 6
16
+ end
13
17
  Process.wait pid
14
- @object.sync
18
+ @instance.sync
15
19
 
16
- assert_equal 5, @a
20
+ assert_equal 5, x
17
21
  end
18
22
 
19
- it 'should confirm a shared variable is removed from #variables.' do
20
- @object.share :@a
21
- @object.unshare :@a
22
- assert_equal true, @object.variables.empty?
23
+ it 'should assert a shared variable is removed from #variables.' do
24
+ x = 5
25
+ @instance.share :x
26
+ @instance.unshare :x
27
+ assert_equal true, @instance.variables.empty?
28
+ end
29
+
30
+ it 'should assert a shared variable is removed from @shared' do
31
+ x = 5
32
+ @instance.share :x
33
+ @instance.fork { }
34
+ assert true, @instance.instance_variable_get(:@shared).has_key?(:x)
35
+
36
+ @instance.unshare :x
37
+ @instance.fork { }
38
+ assert true, @instance.instance_variable_get(:@shared).empty?
23
39
  end
24
40
 
25
41
  end
42
+
26
43
  end
27
44
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: barney
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.8.0
5
+ version: 0.8.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Robert Gleeson
@@ -55,6 +55,7 @@ files:
55
55
  - test/suite/lib/barney/share#fork.rb
56
56
  - test/suite/lib/barney/share#history.rb
57
57
  - test/suite/lib/barney/share#initialize.rb
58
+ - test/suite/lib/barney/share#shared.rb
58
59
  - test/suite/lib/barney/share#synchronize.rb
59
60
  - test/suite/lib/barney/share#unshare.rb
60
61
  has_rdoc: true
@@ -89,5 +90,6 @@ test_files:
89
90
  - test/suite/lib/barney/share#fork.rb
90
91
  - test/suite/lib/barney/share#history.rb
91
92
  - test/suite/lib/barney/share#initialize.rb
93
+ - test/suite/lib/barney/share#shared.rb
92
94
  - test/suite/lib/barney/share#synchronize.rb
93
95
  - test/suite/lib/barney/share#unshare.rb