barney 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,9 @@
1
+ 2011-03-04 Robert Gleeson <rob@flowof.info> v0.5.0
2
+
3
+ * Solve Github Issue no. 3
4
+ * Solve Github Issue no. 2
5
+ * Write a more efficient and easier to understand Barney::Share#sync method.
6
+
1
7
  2011-02-16 Robert Gleeson <rob@flowof.info> v0.4.1
2
8
 
3
9
  * Add http://www.gem-testers.org support.
@@ -9,7 +15,7 @@
9
15
 
10
16
  2011-01-16 Robert Gleeson <rob@flowof.info> v0.3.1
11
17
 
12
- * Solve Github Issue #1.
18
+ * Solve Github Issue no. 1.
13
19
  * Add Barney::Share#pid.
14
20
 
15
21
  2011-01-04 Robert Gleeson <rob@flowof.info> v0.2.0
data/README.md CHANGED
@@ -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.5.0](http://rubydoc.info/gems/barney/0.5.0)
91
92
  * [0.4.1](http://rubydoc.info/gems/barney/0.4.1)
92
93
  * [0.4.0](http://rubydoc.info/gems/barney/0.4.0)
93
94
  * [0.3.1](http://rubydoc.info/gems/barney/0.3.1)
@@ -96,10 +97,7 @@ Okay, now that we've got that out of the way, let's see what using Barney is lik
96
97
 
97
98
  ## License
98
99
 
99
- Barney is released under the LGPL.
100
- You are free to **use** this library in free or commercial software, and license that software however you want,
101
- but as soon as you modify the library itself,
102
- you must share your changes under the same license. :)
100
+ Barney is released under the Lesser GPL(LGPL).
103
101
 
104
102
  ## Install
105
103
 
data/Rakefile CHANGED
@@ -3,5 +3,6 @@ task :test do
3
3
  require 'barney'
4
4
  require 'minitest/spec'
5
5
  require 'minitest/autorun'
6
+ begin; require 'turn'; rescue LoadError; end
6
7
  Dir.glob("test/suite/lib/**/*.rb").each { |test| require_relative test }
7
8
  end
data/lib/barney/share.rb CHANGED
@@ -68,16 +68,15 @@ module Barney
68
68
  # @return [Fixnum] Returns the Process ID(PID) of the spawned child process.
69
69
  def fork &blk
70
70
  raise ArgumentError, "A block or Proc object is expected" unless block_given?
71
-
72
71
  share *@shared.keys if @pid
73
72
 
74
73
  @context = blk.binding
75
74
  @pid = Kernel.fork do
76
75
  blk.call
77
- @shared.each do |variable, hash|
78
- hash[@seq][0].close
79
- hash[@seq][1].write Marshal.dump(eval("#{variable}", @context))
80
- hash[@seq][1].close
76
+ @shared.each do |variable, pipes|
77
+ pipes[@seq][0].close
78
+ pipes[@seq][1].write Marshal.dump(eval("#{variable}", @context))
79
+ pipes[@seq][1].close
81
80
  end
82
81
  end
83
82
 
@@ -89,16 +88,16 @@ module Barney
89
88
  # It will block until the spawned child process has exited.
90
89
  # @return [void]
91
90
  def synchronize
92
- @shared.each do |variable, hash|
91
+ @shared.each do |variable, pipes|
93
92
  Barney::Share.mutex.synchronize do
94
- 0.upto(@seq) do |seq|
95
- unless hash[seq].nil? || hash[seq][0].closed? || hash[seq][1].closed?
96
- hash[seq][1].close
97
- Barney::Share.value = Marshal.load hash[seq][0].read
98
- hash[seq][0].close
99
- object = eval "#{variable} = Barney::Share.value", @context
100
- @history[seq] = { variable => object }
101
- end
93
+ min, max = pipes.keys.min, pipes.keys.max
94
+ min.upto max do |seq|
95
+ pipes[seq][1].close
96
+ Barney::Share.value = Marshal.load pipes[seq][0].read
97
+ pipes[seq][0].close
98
+ object = eval "#{variable} = Barney::Share.value", @context
99
+ @history[seq] = (@history[seq] || {}).merge({ variable => object })
100
+ pipes.delete seq
102
101
  end
103
102
  end
104
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.1'
5
+ VERSION = '0.5.0'
6
6
 
7
7
  end
8
8
 
@@ -1,7 +1,7 @@
1
1
  describe Barney::Share do
2
2
  describe '#fork' do
3
3
 
4
- it 'should return the Process ID(PID) is on success.' do
4
+ it 'should return the Process ID(PID) on success.' do
5
5
  pid = Barney::Share.new.fork { }
6
6
  Process.wait pid
7
7
  assert_equal Fixnum, pid.class
@@ -50,6 +50,25 @@ describe Barney::Share do
50
50
  assert_equal 6, $times
51
51
  end
52
52
 
53
+ it 'should fix Github Issue #2' do
54
+ a,b = 4,5
55
+ @object.share :a
56
+ @object.fork { }
57
+ Process.wait @object.pid
58
+ @object.share :b
59
+ @object.fork { b = 6 }
60
+ @object.sync # will raise NoMethodError if fails.
61
+ end
62
+
63
+ it 'should fix GitHub Issue #3' do
64
+ a,b = 4,5
65
+ @object.share :a, :b
66
+ @object.fork { }
67
+ Process.wait @object.pid
68
+ @object.sync
69
+ assert_equal({ 0 => { :a => 4, :b => 5 } }, @object.history)
70
+ end
71
+
53
72
  end
54
73
  end
55
74
 
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barney
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 4
8
- - 1
9
- version: 0.4.1
4
+ prerelease:
5
+ version: 0.5.0
10
6
  platform: ruby
11
7
  authors:
12
8
  - Robert Gleeson
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-02-16 00:00:00 +00:00
13
+ date: 2011-03-04 00:00:00 +00:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -25,8 +21,6 @@ dependencies:
25
21
  requirements:
26
22
  - - ">="
27
23
  - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
24
  version: "0"
31
25
  type: :development
32
26
  version_requirements: *id001
@@ -38,8 +32,6 @@ dependencies:
38
32
  requirements:
39
33
  - - ">="
40
34
  - !ruby/object:Gem::Version
41
- segments:
42
- - 0
43
35
  version: "0"
44
36
  type: :development
45
37
  version_requirements: *id002
@@ -79,25 +71,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
71
  requirements:
80
72
  - - ">="
81
73
  - !ruby/object:Gem::Version
82
- segments:
83
- - 1
84
- - 9
85
- - 1
86
74
  version: 1.9.1
87
75
  required_rubygems_version: !ruby/object:Gem::Requirement
88
76
  none: false
89
77
  requirements:
90
78
  - - ">="
91
79
  - !ruby/object:Gem::Version
92
- segments:
93
- - 1
94
- - 3
95
- - 6
96
80
  version: 1.3.6
97
81
  requirements: []
98
82
 
99
83
  rubyforge_project: "[none]"
100
- rubygems_version: 1.3.7
84
+ rubygems_version: 1.6.0
101
85
  signing_key:
102
86
  specification_version: 3
103
87
  summary: Barney tries to make the sharing of data between processes as easy and natural as possible.