barney 0.14.0 → 0.15.0
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/.yardopts +0 -1
- data/ChangeLog +13 -1
- data/README.md +19 -59
- data/lib/barney.rb +7 -19
- data/lib/barney/jobs.rb +23 -0
- data/samples/{magic_barney_method.rb → Barney_method.rb} +4 -1
- data/test/suite/lib/barney.rb +2 -2
- data/test/suite/lib/barney/jobs.rb +9 -0
- metadata +6 -4
- data/samples/barney_module.rb +0 -17
data/.yardopts
CHANGED
data/ChangeLog
CHANGED
@@ -1,10 +1,22 @@
|
|
1
|
+
2011-05-25 Robert Gleeson <rob@flowof.info>
|
2
|
+
|
3
|
+
* lib/barney.rb:
|
4
|
+
Release 0.15.0
|
5
|
+
|
6
|
+
|
1
7
|
2011-05-23 Robert Gleeson <rob@flowof.info>
|
2
8
|
|
9
|
+
* lib/barney.rb:
|
10
|
+
Deprecate the Barney module responding to Barney::Share methods.
|
11
|
+
|
12
|
+
* lib/barney.rb lib/barney/jobs.rb:
|
13
|
+
Add Jobs() method.
|
14
|
+
|
3
15
|
* lib/barney.rb:
|
4
16
|
Release 0.14.0
|
5
17
|
|
6
18
|
* lib/barney.rb lib/barney/emptystate.rb test/suite/lib/barney.rb:
|
7
|
-
Add
|
19
|
+
Add Barney() method.
|
8
20
|
|
9
21
|
2011-05-12 Robert Gleeson <rob@flowof.info>
|
10
22
|
|
data/README.md
CHANGED
@@ -3,33 +3,22 @@
|
|
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
|
-
|
7
|
-
|
6
|
+
Underneath the hood, Barney is using the `Marshal` (the module) to serialize objects and send them across pipes created by `IO.pipe`.
|
7
|
+
If an object can't be serialized by `Marshal`, it can't be shared. That means objects such as anonymous modules,
|
8
|
+
anonymous classes, and Proc objects can't be shared by Barney.
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
* Sharable objects
|
13
|
-
Behind the scenes, Barney is using Marshal to send data between processes.
|
14
|
-
Any object that can be dumped through Marshal.dump can be shared.
|
15
|
-
This excludes anonymous modules, anonymous classes, Proc objects, and possibly some other objects I cannot think of.
|
16
|
-
|
17
|
-
* Thread safety
|
18
|
-
Barney is thread-safe as long as one instance of Barney::Share is used per-thread.
|
19
|
-
There is a mutex lock in place, but it only concerns Barney::Share#synchronize, where data is shared among all
|
20
|
-
instances of Barney::Share.
|
10
|
+
Below is an example of how _simple_ it is to use Barney, but please take the time to look at
|
11
|
+
[The Wiki](https://github.com/robgleeson/barney/wiki) if you're interested in Barney, because I cover other APIs
|
12
|
+
and everything else in much more depth.
|
21
13
|
|
22
14
|
Usage
|
23
15
|
-----
|
24
16
|
|
25
|
-
__Magic "Barney" method__
|
26
|
-
|
27
|
-
#!/usr/bin/env ruby
|
28
|
-
# Magic "Barney" method
|
29
17
|
require 'barney'
|
30
|
-
|
18
|
+
|
19
|
+
name = "Robert"
|
20
|
+
|
31
21
|
Barney do
|
32
|
-
name = "Robert"
|
33
22
|
share :name
|
34
23
|
|
35
24
|
fork do
|
@@ -39,38 +28,17 @@ __Magic "Barney" method__
|
|
39
28
|
|
40
29
|
p name # "Rob"
|
41
30
|
|
42
|
-
__Barney module__
|
43
|
-
|
44
|
-
#!/usr/bin/env ruby
|
45
|
-
# Barney module sample
|
46
|
-
# Messages are forwarded onto a single instance of Barney::Share.
|
47
|
-
require 'barney'
|
48
|
-
|
49
|
-
Barney.share :name
|
50
|
-
|
51
|
-
Barney.fork do
|
52
|
-
name.slice! 3..5
|
53
|
-
end
|
54
|
-
|
55
|
-
Barney.wait_all
|
56
|
-
Barney.sync
|
57
|
-
|
58
|
-
p name # "Rob"
|
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
|
-
|
68
31
|
Documentation
|
69
32
|
--------------
|
70
33
|
|
34
|
+
**Wiki**
|
35
|
+
|
36
|
+
* [Wiki](https://github.com/robgleeson/barney/wiki)
|
37
|
+
|
71
38
|
**API**
|
72
39
|
|
73
40
|
* [master (git)](http://rubydoc.info/github/robgleeson/barney/master/)
|
41
|
+
* [0.15.0](http://rubydoc.info/gems/barney/0.15.0/)
|
74
42
|
* [0.14.0](http://rubydoc.info/gems/barney/0.14.0/)
|
75
43
|
* [0.13.0](http://rubydoc.info/gems/barney/0.13.0/)
|
76
44
|
* [0.12.0](http://rubydoc.info/gems/barney/0.12.0/)
|
@@ -80,22 +48,14 @@ Documentation
|
|
80
48
|
* …
|
81
49
|
|
82
50
|
|
51
|
+
**Samples**
|
52
|
+
|
53
|
+
* [Samples](https://github.com/robgleeson/tree/master/samples)
|
83
54
|
|
84
55
|
Install
|
85
56
|
--------
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
gem install barney
|
90
|
-
|
91
|
-
Github
|
92
|
-
|
93
|
-
git clone git://github.com/robgleeson/barney.git
|
94
|
-
cd barney
|
95
|
-
gem build *.gemspec
|
96
|
-
gem install *.gem
|
97
|
-
|
98
|
-
I'm following the [Semantic Versioning](http://www.semver.org) policy.
|
57
|
+
|
58
|
+
$ [sudo] gem install barney
|
99
59
|
|
100
60
|
License
|
101
61
|
--------
|
data/lib/barney.rb
CHANGED
@@ -1,34 +1,22 @@
|
|
1
1
|
require 'thread'
|
2
|
-
require 'barney/share'
|
2
|
+
require 'barney/share'
|
3
|
+
require 'barney/jobs'
|
3
4
|
require 'barney/emptystate'
|
4
5
|
|
5
6
|
module Barney
|
6
7
|
|
7
|
-
VERSION = '0.
|
8
|
+
VERSION = '0.15.0'
|
8
9
|
@proxy = Barney::Share.new
|
9
10
|
|
10
11
|
class << self
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
if @proxy.respond_to? meth
|
17
|
-
@proxy.send meth, *args, &blk
|
18
|
-
else
|
19
|
-
super
|
13
|
+
Barney::Share.instance_methods(false).each do |method|
|
14
|
+
define_method method do |*args, &block|
|
15
|
+
$stderr.puts "[WARNING] Barney.#{method} is deprecated and will be removed in the next release."
|
16
|
+
@proxy.send method, *args, &block
|
20
17
|
end
|
21
18
|
end
|
22
19
|
|
23
|
-
# Ask {Barney} does it respond to _meth_.
|
24
|
-
#
|
25
|
-
# @param [String, Symbol, #to_sym] Name The method name.
|
26
|
-
# @param [Boolean] Scope Pass true to extend scope to include private methods.
|
27
|
-
# @return [Boolean] Return true if {Barney} can respond to _meth_.
|
28
|
-
def respond_to? meth, with_private = false
|
29
|
-
super || @proxy.respond_to?(meth, with_private)
|
30
|
-
end
|
31
|
-
|
32
20
|
end
|
33
21
|
|
34
22
|
end
|
data/lib/barney/jobs.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Returns an Array populated by the return value of the block.
|
2
|
+
# Each block is executed in a subprocess.
|
3
|
+
#
|
4
|
+
# @param [Proc] Block The block to execute in a subprocess.
|
5
|
+
# @param [Fixnum] Processes The number of subprocesses to spawn.
|
6
|
+
# @return [Array<Object>]
|
7
|
+
def Jobs number, &block
|
8
|
+
barney = Barney::Share.new
|
9
|
+
barney.share :queue
|
10
|
+
queue = []
|
11
|
+
|
12
|
+
number.times do
|
13
|
+
barney.fork do
|
14
|
+
queue << block.call
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
barney.wait_all
|
19
|
+
barney.sync
|
20
|
+
|
21
|
+
barney.history.map(&:value).flatten
|
22
|
+
end
|
23
|
+
|
data/test/suite/lib/barney.rb
CHANGED
@@ -11,12 +11,12 @@ end
|
|
11
11
|
|
12
12
|
describe '#Barney' do
|
13
13
|
|
14
|
-
it 'should
|
14
|
+
it 'should synchronize data using the #Barney() method.' do
|
15
15
|
name = 'Robert'
|
16
16
|
|
17
17
|
Barney do
|
18
18
|
share :name
|
19
|
-
fork { name.slice! 3..5
|
19
|
+
fork { name.slice! 3..5}
|
20
20
|
fork { name.slice! 1..2 }
|
21
21
|
end
|
22
22
|
|
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.15.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-25 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -50,11 +50,12 @@ files:
|
|
50
50
|
- README.md
|
51
51
|
- ChangeLog
|
52
52
|
- .gemtest
|
53
|
-
- samples/
|
54
|
-
- samples/magic_barney_method.rb
|
53
|
+
- samples/Barney_method.rb
|
55
54
|
- lib/barney/emptystate.rb
|
55
|
+
- lib/barney/jobs.rb
|
56
56
|
- lib/barney/share.rb
|
57
57
|
- lib/barney.rb
|
58
|
+
- test/suite/lib/barney/jobs.rb
|
58
59
|
- test/suite/lib/barney/share#fork.rb
|
59
60
|
- test/suite/lib/barney/share#history.rb
|
60
61
|
- test/suite/lib/barney/share#initialize.rb
|
@@ -91,6 +92,7 @@ signing_key:
|
|
91
92
|
specification_version: 3
|
92
93
|
summary: Barney tries to make the sharing of data between processes as easy and natural as possible.
|
93
94
|
test_files:
|
95
|
+
- test/suite/lib/barney/jobs.rb
|
94
96
|
- test/suite/lib/barney/share#fork.rb
|
95
97
|
- test/suite/lib/barney/share#history.rb
|
96
98
|
- test/suite/lib/barney/share#initialize.rb
|
data/samples/barney_module.rb
DELETED
@@ -1,17 +0,0 @@
|
|
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"
|