barney 0.13.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +42 -28
- data/README.md +38 -18
- data/lib/barney/emptystate.rb +26 -0
- data/lib/barney/share.rb +5 -11
- data/lib/barney.rb +27 -1
- data/samples/barney_module.rb +17 -0
- data/samples/magic_barney_method.rb +14 -0
- data/test/suite/lib/barney/share#unshare.rb +0 -11
- data/test/suite/lib/barney.rb +16 -0
- metadata +5 -2
data/ChangeLog
CHANGED
@@ -1,62 +1,76 @@
|
|
1
|
+
2011-05-23 Robert Gleeson <rob@flowof.info>
|
2
|
+
|
3
|
+
* lib/barney.rb:
|
4
|
+
Release 0.14.0
|
5
|
+
|
6
|
+
* lib/barney.rb lib/barney/emptystate.rb test/suite/lib/barney.rb:
|
7
|
+
Add magic "Barney" method.
|
8
|
+
|
9
|
+
2011-05-12 Robert Gleeson <rob@flowof.info>
|
10
|
+
|
11
|
+
* lib/barney/share.rb:
|
12
|
+
Barney::Share#unshare no longer removes streams from @shared.
|
13
|
+
This means a variable stops being shared at the next call Share#fork.
|
14
|
+
|
1
15
|
2011-05-09 Robert Gleeson <rob@flowof.info>
|
2
16
|
|
17
|
+
* README.md lib/barney.rb:
|
18
|
+
Release 0.13.0
|
19
|
+
|
3
20
|
* LICENSE README.md:
|
4
|
-
|
5
|
-
|
21
|
+
Change license from Lesser GPL(LGPL) to the MIT license.
|
22
|
+
See LICENSE for details.
|
6
23
|
|
7
24
|
2011-05-03 Robert Gleeson <rob@flowof.info>
|
8
25
|
|
9
|
-
|
10
|
-
|
26
|
+
* lib/barney.rb README.md:
|
27
|
+
Release 0.12.0
|
11
28
|
|
12
|
-
|
13
|
-
|
29
|
+
* lib/barney.rb Rakefile.rb:
|
30
|
+
Add support for 1.8.7
|
14
31
|
|
15
|
-
* lib/barney.rb README.md
|
16
|
-
|
32
|
+
* lib/barney.rb README.md:
|
33
|
+
Release 0.11.0
|
17
34
|
|
18
35
|
* lib/barney/share.rb:
|
19
|
-
|
36
|
+
Rename @context to @scope.
|
20
37
|
|
21
38
|
* lib/barney/share.rb:
|
22
|
-
|
39
|
+
Add Barney::Share#wait_all.
|
23
40
|
|
24
41
|
* test/suite/lib/barney.rb:
|
25
|
-
|
26
|
-
|
27
|
-
* lib/barney.rb:
|
28
|
-
Document Barney.method_missing, and Barney.respond_to?
|
42
|
+
Add test suite for the 'Barney' module.
|
29
43
|
|
30
44
|
* lib/barney.rb:
|
31
|
-
|
45
|
+
Document Barney.method_missing, and Barney.respond_to?
|
32
46
|
|
33
|
-
*
|
34
|
-
|
47
|
+
* lib/barney.rb:
|
48
|
+
Add Barney.respond_to?
|
35
49
|
|
36
50
|
* lib/barney/share.rb:
|
37
|
-
|
51
|
+
Remove Barney::Share#spawn_pipes (private method).
|
38
52
|
|
39
|
-
* lib/barney.rb README.md
|
40
|
-
|
53
|
+
* lib/barney.rb README.md:
|
54
|
+
Release 0.10.1
|
41
55
|
|
42
56
|
* lib/barney/share.rb:
|
43
|
-
|
44
|
-
|
57
|
+
Fix a bug where Barney::Share#history could return unordered/incorrect data
|
58
|
+
when subprocesses are spawned in parallel.
|
45
59
|
|
46
60
|
|
47
61
|
2011-04-23 Robert Gleeson <rob@flowof.info>
|
48
62
|
|
49
63
|
* lib/barney.rb README.md:
|
50
|
-
|
64
|
+
Release 0.10.0
|
51
65
|
|
52
66
|
* lib/barney.rb:
|
53
|
-
|
54
|
-
|
67
|
+
Add Barney.method_missing …
|
68
|
+
Messages are passed onto an instance of Barney::Share.
|
55
69
|
|
56
70
|
* lib/barney.rb README.md:
|
57
|
-
|
71
|
+
Release 0.9.1
|
58
72
|
|
59
73
|
* lib/barney/share.rb:
|
60
|
-
|
61
|
-
|
74
|
+
Fix a bug where Barney::Share#share could return nil.
|
75
|
+
If there were no duplicates in @variables, `nil` would be returned.
|
62
76
|
|
data/README.md
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
Barney makes sharing data between processes easy and natural by providing a simple and easy to use DSL.
|
4
4
|
Barney is supported on any Ruby implementation that supports 1.8.7+, 1.9.1+, and that implements `Kernel.fork`.
|
5
5
|
|
6
|
+
If you're looking for a library to do parallel jobs, check out [Parallel](https://github.com/grosser/parallel).
|
7
|
+
While possible in Barney, it was never a design goal and I'd definitely recommend you check out _Parallel_ instead.
|
8
|
+
|
6
9
|
Limitations
|
7
10
|
-----------
|
8
11
|
|
@@ -19,43 +22,61 @@ Limitations
|
|
19
22
|
Usage
|
20
23
|
-----
|
21
24
|
|
25
|
+
__Magic "Barney" method__
|
26
|
+
|
22
27
|
#!/usr/bin/env ruby
|
28
|
+
# Magic "Barney" method
|
23
29
|
require 'barney'
|
24
30
|
|
25
|
-
Barney
|
26
|
-
|
31
|
+
Barney do
|
32
|
+
name = "Robert"
|
33
|
+
share :name
|
27
34
|
|
28
|
-
|
29
|
-
|
35
|
+
fork do
|
36
|
+
name.slice! 3..5
|
37
|
+
end
|
30
38
|
end
|
31
39
|
|
32
|
-
|
33
|
-
Barney.sync
|
40
|
+
p name # "Rob"
|
34
41
|
|
35
|
-
|
42
|
+
__Barney module__
|
36
43
|
|
37
|
-
|
38
|
-
|
39
|
-
|
44
|
+
#!/usr/bin/env ruby
|
45
|
+
# Barney module sample
|
46
|
+
# Messages are forwarded onto a single instance of Barney::Share.
|
47
|
+
require 'barney'
|
40
48
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
49
|
+
Barney.share :name
|
50
|
+
|
51
|
+
Barney.fork do
|
52
|
+
name.slice! 3..5
|
53
|
+
end
|
54
|
+
|
55
|
+
Barney.wait_all
|
56
|
+
Barney.sync
|
45
57
|
|
58
|
+
p name # "Rob"
|
46
59
|
|
60
|
+
* _More!_
|
61
|
+
Check out the [samples](https://github.com/robgleeson/barney/tree/master/samples) directory.
|
62
|
+
Check out the API docs, too.
|
63
|
+
|
64
|
+
* _Notes_
|
65
|
+
The DSL is implemented in _Barney::Share_.
|
66
|
+
You can create instances of(or subclasses) of _Barney::Share_ if you need to.
|
67
|
+
|
47
68
|
Documentation
|
48
69
|
--------------
|
49
70
|
|
50
71
|
**API**
|
51
72
|
|
52
73
|
* [master (git)](http://rubydoc.info/github/robgleeson/barney/master/)
|
74
|
+
* [0.14.0](http://rubydoc.info/gems/barney/0.14.0/)
|
53
75
|
* [0.13.0](http://rubydoc.info/gems/barney/0.13.0/)
|
54
76
|
* [0.12.0](http://rubydoc.info/gems/barney/0.12.0/)
|
55
77
|
* [0.11.0](http://rubydoc.info/gems/barney/0.11.0/)
|
56
78
|
* [0.10.1](http://rubydoc.info/gems/barney/0.10.1/)
|
57
79
|
* [0.10.0](http://rubydoc.info/gems/barney/0.10.0/)
|
58
|
-
* [0.9.1](http://rubydoc.info/gems/barney/0.9.1/)
|
59
80
|
* …
|
60
81
|
|
61
82
|
|
@@ -80,8 +101,7 @@ License
|
|
80
101
|
--------
|
81
102
|
|
82
103
|
Barney is released under the [_MIT License_](http://en.wikipedia.org/wiki/MIT_License).
|
83
|
-
See [LICENSE](http://github.com/robgleeson/barney/blob/master/README.md) for details
|
84
|
-
|
85
|
-
Prior to 0.13.0, Barney was released under the Lesser GPL(LGPL).
|
104
|
+
See [LICENSE](http://github.com/robgleeson/barney/blob/master/README.md) for details!
|
105
|
+
All versions before 0.13.0 are Lesser GPL(LGPL) licensed.
|
86
106
|
|
87
107
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Barney
|
2
|
+
|
3
|
+
class EmptyState
|
4
|
+
attr_reader :__barney__
|
5
|
+
|
6
|
+
Barney::Share.instance_methods(false).each do |meth|
|
7
|
+
define_method meth do |*args, &block|
|
8
|
+
@__barney__.send meth, *args, &block
|
9
|
+
end
|
10
|
+
|
11
|
+
undef_method :fork
|
12
|
+
|
13
|
+
define_method :fork do |*args, &block|
|
14
|
+
@__barney__.send :fork, *args, &block
|
15
|
+
@__barney__.sync
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@__barney__ = Barney::Share.new
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
data/lib/barney/share.rb
CHANGED
@@ -64,20 +64,14 @@ module Barney
|
|
64
64
|
# @param [Symbol, #to_sym] Variable Accepts the name(s) of the variables or constants you want to stop sharing.
|
65
65
|
# @return [Array<Symbol>] Returns a list of the variables that are still being shared.
|
66
66
|
def unshare *variables
|
67
|
-
variables.each
|
68
|
-
variable = variable.to_sym
|
69
|
-
@streams.delete_if { |stream| stream.variable == variable }
|
70
|
-
@variables.delete variable
|
71
|
-
end
|
67
|
+
variables.each { |variable| @variables.delete variable.to_sym }
|
72
68
|
@variables
|
73
69
|
end
|
74
70
|
|
75
71
|
# Collect the status of all subprocesses spawned by a {Barney::Share Barney::Share} instance.
|
76
72
|
# @return [void]
|
77
73
|
def wait_all
|
78
|
-
@pids.each
|
79
|
-
Process.wait pid
|
80
|
-
end
|
74
|
+
@pids.each { |pid| Process.wait pid }
|
81
75
|
@pids.clear
|
82
76
|
end
|
83
77
|
|
@@ -91,20 +85,20 @@ module Barney
|
|
91
85
|
raise ArgumentError, "A block or Proc object is expected" unless block_given?
|
92
86
|
@scope = block.binding
|
93
87
|
|
94
|
-
|
88
|
+
streams = Array.new @variables.size do |index|
|
95
89
|
StreamPair.new @variables[index], *IO.pipe
|
96
90
|
end
|
97
91
|
|
98
92
|
@pid = Kernel.fork do
|
99
93
|
block.call
|
100
|
-
|
94
|
+
streams.each do |stream|
|
101
95
|
stream.in.close
|
102
96
|
stream.out.write Marshal.dump(@scope.eval("#{stream.variable}"))
|
103
97
|
stream.out.close
|
104
98
|
end
|
105
99
|
end
|
106
100
|
|
107
|
-
@streams.push *
|
101
|
+
@streams.push *streams
|
108
102
|
@pids.push @pid
|
109
103
|
@pid
|
110
104
|
end
|
data/lib/barney.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'thread'
|
2
2
|
require 'barney/share'
|
3
|
+
require 'barney/emptystate'
|
3
4
|
|
4
5
|
module Barney
|
5
6
|
|
6
|
-
VERSION = '0.
|
7
|
+
VERSION = '0.14.0'
|
7
8
|
@proxy = Barney::Share.new
|
8
9
|
|
9
10
|
class << self
|
@@ -31,3 +32,28 @@ module Barney
|
|
31
32
|
end
|
32
33
|
|
33
34
|
end
|
35
|
+
|
36
|
+
# Evaluates a block with access to all the methods available to a {Barney::Share Barney::Share} instance.
|
37
|
+
# Collecting the status of subprocesses and {Barney::Share#sync synchronization} is handled for you.
|
38
|
+
#
|
39
|
+
# @example
|
40
|
+
# name = "Robert"
|
41
|
+
#
|
42
|
+
# Barney do
|
43
|
+
# share :name
|
44
|
+
#
|
45
|
+
# fork do
|
46
|
+
# name.slice! 0..2
|
47
|
+
# end
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# p name # "Rob"
|
51
|
+
#
|
52
|
+
# @raise [ArgumentError] If no block is supplied.
|
53
|
+
# @return [void]
|
54
|
+
def Barney &block
|
55
|
+
raise ArgumentError, "Block expected" unless block_given?
|
56
|
+
emptystate = Barney::EmptyState.new
|
57
|
+
emptystate.instance_eval &block
|
58
|
+
emptystate.__barney__.wait_all
|
59
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Barney module sample
|
4
|
+
# Messages are forwarded onto a single instance of Barney::Share.
|
5
|
+
|
6
|
+
require 'barney'
|
7
|
+
|
8
|
+
Barney.share :name
|
9
|
+
|
10
|
+
Barney.fork do
|
11
|
+
name.slice! 3..5
|
12
|
+
end
|
13
|
+
|
14
|
+
Barney.wait_all
|
15
|
+
Barney.sync
|
16
|
+
|
17
|
+
p name # "Rob"
|
@@ -27,17 +27,6 @@ describe Barney::Share do
|
|
27
27
|
assert_equal true, @instance.variables.empty?
|
28
28
|
end
|
29
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_equal :x, @instance.instance_variable_get(:@streams).first.variable
|
35
|
-
|
36
|
-
@instance.unshare :x
|
37
|
-
@instance.fork { }
|
38
|
-
assert_equal true, @instance.instance_variable_get(:@streams).empty?
|
39
|
-
end
|
40
|
-
|
41
30
|
end
|
42
31
|
|
43
32
|
end
|
data/test/suite/lib/barney.rb
CHANGED
@@ -8,3 +8,19 @@ describe 'Barney' do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
end
|
11
|
+
|
12
|
+
describe '#Barney' do
|
13
|
+
|
14
|
+
it 'should..' do
|
15
|
+
name = 'Robert'
|
16
|
+
|
17
|
+
Barney do
|
18
|
+
share :name
|
19
|
+
fork { name.slice! 3..5 }
|
20
|
+
fork { name.slice! 1..2 }
|
21
|
+
end
|
22
|
+
|
23
|
+
assert_equal "R", name
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: barney
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.14.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Robert Gleeson
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-23 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -50,6 +50,9 @@ files:
|
|
50
50
|
- README.md
|
51
51
|
- ChangeLog
|
52
52
|
- .gemtest
|
53
|
+
- samples/barney_module.rb
|
54
|
+
- samples/magic_barney_method.rb
|
55
|
+
- lib/barney/emptystate.rb
|
53
56
|
- lib/barney/share.rb
|
54
57
|
- lib/barney.rb
|
55
58
|
- test/suite/lib/barney/share#fork.rb
|