barney 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
data/.yardopts CHANGED
@@ -2,7 +2,6 @@
2
2
  --no-private
3
3
  --hide-void-return
4
4
  --no-cache
5
- --main README.md
6
5
  -
7
6
  LICENSE
8
7
  ChangeLog
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 magic "Barney" method.
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
- 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.
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
- Limitations
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
- RubyGems.org
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.14.0'
8
+ VERSION = '0.15.0'
8
9
  @proxy = Barney::Share.new
9
10
 
10
11
  class << self
11
12
 
12
- # Forward message to an instance of {Barney::Share Barney::Share}.
13
- #
14
- # @see Barney::Share Barney::Share.
15
- def method_missing meth, *args, &blk
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
@@ -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
+
@@ -4,11 +4,14 @@
4
4
 
5
5
  require 'barney'
6
6
 
7
+ name = 'Robert'
8
+
7
9
  Barney do
8
- name = "Robert"
9
10
  share :name
10
11
 
11
12
  fork do
12
13
  name.slice! 3..5
13
14
  end
14
15
  end
16
+
17
+ p name # "Rob"
@@ -11,12 +11,12 @@ end
11
11
 
12
12
  describe '#Barney' do
13
13
 
14
- it 'should..' do
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
 
@@ -0,0 +1,9 @@
1
+ describe '#Jobs' do
2
+
3
+ it 'should spawn workers, and share their return value with the parent.' do
4
+ result = Jobs(5) { 42 }
5
+ assert_equal [42, 42, 42, 42, 42], result
6
+ end
7
+
8
+
9
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: barney
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.14.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-23 00:00:00 +01:00
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/barney_module.rb
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
@@ -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"