barney 0.15.1 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ .baretest_*
2
+ docs/*
3
+ doc/*
4
+ .yardoc/*
5
+ .DS_Store
6
+ *.gem
7
+ *.rbc
@@ -0,0 +1,10 @@
1
+ script: bundle exec ruby -I lib -r'rubygems' -r'bundler/setup' test/setup.rb
2
+
3
+ rvm:
4
+ - 1.8.7
5
+ - 1.9.1
6
+ - 1.9.2
7
+ - ruby-head
8
+ - ree
9
+ - rbx
10
+ - rbx-2.0.0pre
data/.yardopts CHANGED
@@ -3,6 +3,6 @@
3
3
  --hide-void-return
4
4
  --no-cache
5
5
  -
6
- LICENSE
6
+ LICENSE.txt
7
7
  ChangeLog
8
8
 
data/ChangeLog CHANGED
@@ -1,10 +1,68 @@
1
+
2
+ 2011-06-29 Robert Gleeson <rob@flowof.info>
3
+
4
+ * lib/barney.rb:
5
+ Release 0.16.0
6
+
7
+ * test/suite/warnings.rb test/setup.rb:
8
+ Assert warnings will not be emitted.
9
+
10
+ * lib/barney/share.rb lib/barney/methodlookup.rb lib/barney/core_ext/barney.rb:
11
+ Don't emit warnings in -W2 mode.
12
+
13
+ * lib/barney/share.rb:
14
+ Rename Thread.current[:'__BARNEY__'] to Thread.current[:BARNEY_SERIALIZED_OBJECT]
15
+
16
+ 2011-06-26 Robert Gleeson <rob@flowof.info>
17
+
18
+ * lib/barney/methodlookup.rb:
19
+ Raise a NameError if @__barney__ is defined in the calling scope of passed block.
20
+
21
+ 2011-06-18 Robert Gleeson <rob@flowof.info>
22
+
23
+ * lib/barney/core_ext/jobs.rb:
24
+ Restrict Array#flatten from recursing more then once. Bug fix.
25
+
26
+ 2011-06-13 Robert Gleeson <rob@flowof.info>
27
+
28
+ * lib/barney/methodlookup.rb:
29
+ The methods #share, #unshare, and #fork are the only methods available to a block passed to Barney().
30
+
31
+ * lib/barney.rb:
32
+ Remove deprecated methods from Barney module.
33
+
34
+ * lib/barney/methodlookup.rb:
35
+ Add Barney::MethodLookup.
36
+
37
+ * lib/barney/emptystate.rb:
38
+ Remove Barney::EmptyState.
39
+
40
+ * lib/barney/core_ext.rb lib/barney/core_ext/barney.rb lib/barney/core_ext/jobs.rb:
41
+ Separate core_ext.rb into core_ext/barney.rb and core_ext/jobs.rb.
42
+
43
+
44
+ 2011-06-11 Robert Gleeson <rob@flowof.info>
45
+
46
+ * lib/barney/share.rb:
47
+ Remove Mutex.
48
+ Remain thread-safe when one Barney::Share instance is used per-thread.
49
+
1
50
  2011-05-25 Robert Gleeson <rob@flowof.info>
2
51
 
52
+ * lib/barney/core_ext.rb:
53
+ Add Barney() and Jobs() methods to lib/barney/core_ext.rb
54
+
55
+ * lib/barney.rb:
56
+ Remove Barney() method from lib/barney.rb
57
+
58
+ * lib/barney/jobs.rb:
59
+ Remove file.
60
+
3
61
  * lib/barney.rb:
4
62
  Release 0.15.1
5
63
 
6
64
  * lib/barney/jobs.rb:
7
- Jobs() should raise an ArgumentError if block is missing.
65
+ Jobs() will raise an ArgumentError if block is missing.
8
66
 
9
67
  * lib/barney.rb:
10
68
  Release 0.15.0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ # This file is for Travis (travis-ci.org).
2
+ source :gemcutter
3
+ gem 'minitest'
@@ -0,0 +1,20 @@
1
+ Copyright (C) 2011 by Robert Gleeson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
20
+
data/README.md CHANGED
@@ -3,41 +3,66 @@
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
- Underneath the hood, Barney is using the `Marshal` (the module) to serialize objects and send them across pipes created by `IO.pipe`.
6
+ Underneath the hood, Barney is using `Marshal` (the module) to serialize objects and send them across pipes created by `IO.pipe`.
7
7
  If an object can't be serialized by `Marshal`, it can't be shared. That means objects such as anonymous modules,
8
8
  anonymous classes, and Proc objects can't be shared by Barney.
9
9
 
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.
10
+ I'll give a brief overview of the public API down below.
11
+ The README isn't meant to be the go-to for documentation, so if you'd like to learn more the [Guides](http://github.com/robgleeson/barney/wiki)
12
+ have been written to help you along your way.
13
+ The [API documentation](http://rubydoc.info/github/robgleeson/barney/master/) is written using YARD and takes full advantage of its features.
14
+
13
15
 
14
16
  Usage
15
17
  -----
16
18
 
17
- require 'barney'
18
-
19
- name = "Robert"
20
-
21
- Barney do
22
- share :name
19
+ **The Barney method**
20
+ The Barney method executes each subprocess sequentially so shared data from the first subprocess is available to the next subprocess.
21
+ It is especially useful if you want to perform some operation that should be restricted to a separate process, but be able to share the result
22
+ of that operation with the parent process.
23
+
24
+ ```ruby
25
+ #!/usr/bin/env ruby
26
+ require 'barney'
27
+
28
+ Barney do
29
+ name = "Robert"
30
+ share :name
31
+
32
+ fork do
33
+ name.slice! 3..5
34
+ end
35
+
36
+ p name # "Rob"
37
+ end
38
+ ```
39
+
40
+ **The Jobs method**
41
+ The Jobs method is especially designed for running multiple jobs in parallel.
42
+ The passed block is executed in one or more subprocesses, with the return value of each subprocess returned to you in an Array.
43
+
44
+ ```ruby
45
+ #!/usr/bin/env ruby
46
+ require 'barney'
23
47
 
24
- fork do
25
- name.slice! 3..5
26
- end
27
- end
48
+ number = 21
49
+ results = Jobs(3) { number + number }
50
+ p results # [42, 42, 42]
51
+ ```
52
+
28
53
 
29
- p name # "Rob"
30
54
 
31
55
  Documentation
32
56
  --------------
33
57
 
34
- **Wiki**
58
+ **Guides**
35
59
 
36
60
  * [Wiki](https://github.com/robgleeson/barney/wiki)
37
61
 
38
62
  **API**
39
63
 
40
64
  * [master (git)](http://rubydoc.info/github/robgleeson/barney/master/)
65
+ * [0.16.0](http://rubydoc.info/gems/barney/0.16.0/)
41
66
  * [0.15.1](http://rubydoc.info/gems/barney/0.15.0/)
42
67
  * [0.15.0](http://rubydoc.info/gems/barney/0.15.0/)
43
68
  * [0.14.0](http://rubydoc.info/gems/barney/0.14.0/)
@@ -51,7 +76,7 @@ Documentation
51
76
 
52
77
  **Samples**
53
78
 
54
- * [Samples](https://github.com/robgleeson/tree/master/samples)
79
+ * [Samples](https://github.com/robgleeson/barney/tree/master/samples)
55
80
 
56
81
  Install
57
82
  --------
data/Rakefile CHANGED
@@ -1,14 +1,8 @@
1
1
  desc 'Run test suite.'
2
2
  task :test do
3
3
  $LOAD_PATH.unshift './lib'
4
- require 'barney'
5
- require 'minitest/spec'
6
- require 'minitest/autorun'
7
- Dir.glob("test/suite/lib/**/*.rb").each { |test| require "./#{test}" }
4
+ require './test/setup'
8
5
  end
9
6
 
10
7
  task :default => :test
11
8
 
12
- task :rvm_test do
13
- puts `rvm 1.8.7,rbx-1.2.2,1.9.2 exec rake test`
14
- end
@@ -0,0 +1,25 @@
1
+ # -*- coding: UTF-8 -*-
2
+
3
+ $LOAD_PATH.unshift './lib'
4
+ require 'barney'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "barney"
8
+ s.version = Barney::VERSION
9
+ s.authors = ["Robert Gleeson"]
10
+ s.email = "rob@flowof.info"
11
+ s.homepage = "http://github.com/robgleeson/barney"
12
+ s.summary = "Barney tries to make the sharing of data between processes as easy and natural as possible."
13
+ s.description = s.summary
14
+
15
+ s.files = `git ls-files`.each_line.map(&:chomp)
16
+ s.test_files = Dir.glob "test/**/*.rb"
17
+
18
+ s.platform = Gem::Platform::RUBY
19
+ s.require_path = 'lib'
20
+ s.rubyforge_project = '[none]'
21
+ s.required_rubygems_version = '>= 1.3.6'
22
+
23
+ s.add_development_dependency 'yard'
24
+ s.add_development_dependency 'bluecloth' # for yard+markdown.
25
+ end
@@ -1,47 +1,11 @@
1
1
  require 'thread'
2
2
  require 'barney/share'
3
- require 'barney/jobs'
4
- require 'barney/emptystate'
3
+ require 'barney/methodlookup'
4
+ require 'barney/core_ext/barney'
5
+ require 'barney/core_ext/jobs'
5
6
 
6
7
  module Barney
7
-
8
- VERSION = '0.15.1'
9
- @proxy = Barney::Share.new
10
-
11
- class << self
12
-
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
17
- end
18
- end
19
-
20
- end
21
-
8
+ VERSION = '0.16.0'
22
9
  end
23
10
 
24
- # Evaluates a block with access to all the methods available to a {Barney::Share Barney::Share} instance.
25
- # Collecting the status of subprocesses and {Barney::Share#sync synchronization} is handled for you.
26
- #
27
- # @example
28
- # name = "Robert"
29
- #
30
- # Barney do
31
- # share :name
32
- #
33
- # fork do
34
- # name.slice! 0..2
35
- # end
36
- # end
37
- #
38
- # p name # "Rob"
39
- #
40
- # @raise [ArgumentError] If no block is supplied.
41
- # @return [void]
42
- def Barney &block
43
- raise ArgumentError, "Block expected" unless block_given?
44
- emptystate = Barney::EmptyState.new
45
- emptystate.instance_eval &block
46
- emptystate.__barney__.wait_all
47
- end
11
+
@@ -0,0 +1,31 @@
1
+ # Evaluates a block in the calling scope but provides access to the {Barney::Share#share},
2
+ # {Barney::Share#unshare}, and {Barney::Share#fork} methods.
3
+ # Collecting the status of subprocesses and {Barney::Share#sync synchronization} is handled for you.
4
+ #
5
+ # @example
6
+ #
7
+ # Barney do
8
+ # name = "Robert"
9
+ # share :name
10
+ #
11
+ # fork do
12
+ # name.slice! 3..5
13
+ # end
14
+ #
15
+ # p name # "Rob"
16
+ # end
17
+ #
18
+ #
19
+ # @raise [ArgumentError] If no block is supplied.
20
+ # @raise [NameError] If @__barney__ is defined in the binding for _block_.
21
+ # @return [void]
22
+ def Barney &block
23
+ raise ArgumentError, "Block expected" unless block_given?
24
+
25
+ begin
26
+ Barney::MethodLookup.inject!(&block)
27
+ block.call
28
+ ensure
29
+ Barney::MethodLookup.deject!(&block)
30
+ end
31
+ end
@@ -1,5 +1,4 @@
1
- # Returns an Array populated by the return value of a block.
2
- # Each block is executed in a subprocess.
1
+ # Runs a block in one or more subprocesses, returning the return value of the block everytime it is executed.
3
2
  #
4
3
  # @example
5
4
  # results = Jobs(5) { 42 }
@@ -7,24 +6,23 @@
7
6
  #
8
7
  # @param [Proc] Block The block to execute in a subprocess.
9
8
  # @param [Fixnum] Processes The number of subprocesses to spawn.
10
- # @raise [ArgumentError] If block is missing.
9
+ # @raise [ArgumentError] If no block is supplied.
11
10
  # @return [Array<Object>]
12
- def Jobs number, &block
13
- raise ArgumentError, 'block expected' unless block_given?
11
+ def Jobs processes
12
+ raise ArgumentError, 'Block expected' unless block_given?
14
13
 
15
14
  barney = Barney::Share.new
16
15
  barney.share :queue
17
16
  queue = []
18
17
 
19
- number.times do
18
+ processes.times do
20
19
  barney.fork do
21
- queue << block.call
20
+ queue.push yield
22
21
  end
23
22
  end
24
23
 
25
24
  barney.wait_all
26
25
  barney.sync
27
26
 
28
- barney.history.map(&:value).flatten
27
+ barney.history.map(&:value).flatten 1
29
28
  end
30
-
@@ -0,0 +1,61 @@
1
+ module Barney
2
+ module MethodLookup
3
+
4
+ class << self
5
+
6
+ # Extends the "self" referenced by _block_ with a _share_, _unshare_, and _fork_ method.
7
+ #
8
+ # @api private
9
+ # @param [Proc] Block
10
+ # @raise [NameError] If @__barney__ is defined in the binding for _block_.
11
+ # @return [void]
12
+ def inject! &block
13
+ module_eval do
14
+ def share *variables
15
+ @__barney__.share(*variables)
16
+ end
17
+
18
+ def unshare *variables
19
+ @__barney__.unshare(*variables)
20
+ end
21
+
22
+ def fork &block
23
+ @__barney__.fork(&block)
24
+ @__barney__.wait_all
25
+ @__barney__.sync
26
+ end
27
+ end
28
+
29
+ target = block.binding.eval "self"
30
+ scope_polluted = target.instance_variable_defined? :@__barney__
31
+
32
+ if scope_polluted
33
+ raise NameError, "The instance variable @__barney__ has already been defined!\n" \
34
+ "Barney would like to use it, but it looks like you are using it for something else."
35
+ else
36
+ target.instance_variable_set :@__barney__, Barney::Share.new
37
+ target.extend Barney::MethodLookup
38
+ end
39
+ end
40
+
41
+ # Removes _share_, _unshare_, and _fork_ from the "self" referenced by _block_.
42
+ # Future method calls for _share_, _unshare_, and _fork_ will be made against "self",
43
+ # its superclasses, or modules it includes.
44
+ #
45
+ # @api private
46
+ # @param [Proc] Block
47
+ # @return [void]
48
+ def deject! &block
49
+ target = block.binding.eval "self"
50
+ target.send :remove_instance_variable, :@__barney__ rescue nil
51
+
52
+ remove_method :share
53
+ remove_method :unshare
54
+ remove_method :fork
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+ end
61
+
@@ -12,20 +12,6 @@ module Barney
12
12
  # @attr [Object] value The value of the variable.
13
13
  HistoryItem = Struct.new :variable, :value
14
14
 
15
- @mutex = Mutex.new
16
-
17
- class << self
18
- # Returns the last value read from a spawned child process.
19
- # @api private
20
- # @return [Object]
21
- attr_accessor :value
22
-
23
- # Returns a Mutex that is used by the {Barney::Share#sync} method.
24
- # @api private
25
- # @return [Mutex]
26
- attr_reader :mutex
27
- end
28
-
29
15
  # Returns a list of all variables or constants being shared for an instance of {Barney::Share}.
30
16
  # @return [Array<Symbol>]
31
17
  attr_reader :variables
@@ -55,7 +41,7 @@ module Barney
55
41
  # @param [Symbol, #to_sym] Variable Accepts the name(s) of the variables or constants you want to share.
56
42
  # @return [Array<Symbol>] Returns a list of all variables that are being shared.
57
43
  def share *variables
58
- @variables.push *variables.map(&:to_sym)
44
+ @variables.push(*variables.map(&:to_sym))
59
45
  @variables.uniq!
60
46
  @variables
61
47
  end
@@ -98,7 +84,7 @@ module Barney
98
84
  end
99
85
  end
100
86
 
101
- @streams.push *streams
87
+ @streams.push(*streams)
102
88
  @pids.push @pid
103
89
  @pid
104
90
  end
@@ -106,16 +92,16 @@ module Barney
106
92
  # Synchronizes data between the parent and child process.
107
93
  # @return [void]
108
94
  def synchronize
109
- Barney::Share.mutex.synchronize do
110
- @streams.each do |stream|
111
- stream.out.close
112
- Barney::Share.value = Marshal.load stream.in.read
113
- stream.in.close
114
- value = @scope.eval "#{stream.variable} = Barney::Share.value"
115
- @history.push HistoryItem.new(stream.variable, value)
116
- end
117
- @streams.clear
118
- end
95
+ @streams.each do |stream|
96
+ stream.out.close
97
+ Thread.current[:BARNEY_SERIALIZED_OBJECT] = Marshal.load stream.in.read
98
+ stream.in.close
99
+ value = @scope.eval "#{stream.variable} = ::Thread.current[:BARNEY_SERIALIZED_OBJECT]"
100
+ @history.push HistoryItem.new(stream.variable, value)
101
+ end
102
+
103
+ Thread.current[:BARNEY_SERIALIZED_OBJECT] = nil
104
+ @streams.clear
119
105
  end
120
106
  alias_method :sync, :synchronize
121
107
 
@@ -0,0 +1,22 @@
1
+ require 'barney'
2
+
3
+ class Example
4
+
5
+ attr_reader :name
6
+
7
+ def initialize
8
+ @name = "Rob"
9
+ end
10
+
11
+ def execute!
12
+ Barney do
13
+ share :@name
14
+ fork { @name = "Bob" }
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+ example = Example.new
21
+ example.execute!
22
+ p example.name # => "Bob"
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ require 'barney'
3
+
4
+ number = 21
5
+ results = Jobs(5) { number + number }
6
+ p results # => [42, 42, 42, 42, 42]
@@ -0,0 +1,20 @@
1
+ class MethodScopeTest
2
+
3
+ attr_reader :run
4
+
5
+ def initialize
6
+ @run = false
7
+ end
8
+
9
+ def run
10
+ @run = true
11
+ end
12
+
13
+ def execute
14
+ Barney do
15
+ share :@run
16
+ fork { run }
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,16 @@
1
+ class SelfScopeTest
2
+
3
+ attr_reader :self
4
+
5
+ def initialize
6
+ @self = nil
7
+ end
8
+
9
+ def execute
10
+ Barney do
11
+ share :@self
12
+ fork { @self = self.class.to_s }
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,7 @@
1
+ require 'barney'
2
+ require 'open3'
3
+ gem 'minitest'
4
+ require 'minitest/spec'
5
+ require 'minitest/autorun'
6
+ Dir.glob("test/helpers/**/*.rb").each { |helper| require "./#{helper}" }
7
+ Dir.glob("test/suite/**/*.rb").each { |test| require "./#{test}" }
@@ -0,0 +1,84 @@
1
+ describe '#Barney' do
2
+
3
+ describe 'synchronization' do
4
+ before do
5
+ @name = nil
6
+ end
7
+
8
+ it 'should synchronize a local variable.' do
9
+ name = 'Robert'
10
+
11
+ Barney do
12
+ share :name
13
+ fork { name.slice! 3..5}
14
+ fork { name.slice! 1..2 }
15
+ end
16
+
17
+ assert_equal "R", name
18
+ end
19
+
20
+ it 'should synchronize an instance variable.' do
21
+ @name = 'Robert'
22
+
23
+ Barney do
24
+ share :@name
25
+ fork { @name.slice! 3..5 }
26
+ fork { @name.slice! 1..2 }
27
+ end
28
+
29
+ assert_equal "R", @name
30
+ end
31
+ end
32
+
33
+ describe 'scope' do
34
+ it 'should raise a NameError when @__barney__ is already defined.' do
35
+ @__barney__ = nil
36
+ assert_raises NameError do
37
+ Barney {}
38
+ end
39
+ end
40
+
41
+ it 'should always unpollute the calling scope, even if an exception is raised in the passed block.' do
42
+ begin
43
+ Barney do
44
+ raise
45
+ end
46
+ rescue
47
+ end
48
+
49
+ assert_equal false , instance_variable_defined?(:@__barney__)
50
+ assert_equal Kernel, method(:fork).owner
51
+ assert_raises(NameError) { method(:share).owner }
52
+ assert_raises(NameError) { method(:unshare).owner }
53
+ end
54
+
55
+ it 'should be able to call methods in the calling scope.' do
56
+ klass = MethodScopeTest.new
57
+ klass.execute
58
+
59
+ assert_equal true, klass.run
60
+ end
61
+
62
+ it 'should evaluate the passed block in the context it was created in.' do
63
+ klass = SelfScopeTest.new
64
+ klass.execute
65
+
66
+ assert_equal "SelfScopeTest", klass.self
67
+ end
68
+
69
+ it 'should inject and then deject #share, #unshare and #fork on the calling self.' do
70
+ Barney do
71
+ assert_equal "#Barney::scope" , self.class.to_s
72
+ assert_equal Barney::MethodLookup, method(:share).owner
73
+ assert_equal Barney::MethodLookup, method(:unshare).owner
74
+ assert_equal Barney::MethodLookup, method(:fork).owner
75
+ end
76
+
77
+ assert_equal "#Barney::scope", self.class.to_s
78
+ assert_raises(NameError) { method(:share) }
79
+ assert_raises(NameError) { method(:unshare) }
80
+ assert_equal Kernel, method(:fork).owner
81
+ end
82
+ end
83
+
84
+ end
@@ -0,0 +1,20 @@
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
+ it 'should have execute the passed block in the calling scope.' do
10
+ number = 21
11
+ result = Jobs(5) { number + number }
12
+ assert_equal [42, 42, 42, 42, 42], result
13
+ end
14
+
15
+ it 'should return an array of arrays when an array is returned by a subprocess.' do
16
+ result = Jobs(2) { [1] }
17
+ assert_equal [[1], [1]], result
18
+ end
19
+
20
+ end
@@ -23,12 +23,12 @@ describe Barney::Share do
23
23
  obj.share :str
24
24
 
25
25
  %w(r u b y).each do |letter|
26
- pids << obj.fork do
26
+ obj.fork do
27
27
  str << letter
28
28
  end
29
29
  end
30
30
 
31
- pids.each { |pid| Process.wait pid }
31
+ obj.wait_all
32
32
  obj.sync
33
33
 
34
34
  str = obj.history.map(&:value).join
@@ -0,0 +1,8 @@
1
+ describe 'warnings' do
2
+ it 'should emit none' do
3
+ Open3.popen3 "ruby -I lib -r'barney' -W -e ''" do |stdin, stdout, stderr|
4
+ warnings = stderr.read
5
+ assert warnings.empty?, "Warnings: #{warnings}"
6
+ end
7
+ end
8
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: barney
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.15.1
5
+ version: 0.16.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-25 00:00:00 +01:00
13
+ date: 2011-06-29 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -44,25 +44,35 @@ extensions: []
44
44
  extra_rdoc_files: []
45
45
 
46
46
  files:
47
- - Rakefile
48
- - LICENSE
47
+ - .gemtest
48
+ - .gitignore
49
+ - .travis.yml
49
50
  - .yardopts
50
- - README.md
51
51
  - ChangeLog
52
- - .gemtest
53
- - samples/Barney_method.rb
54
- - lib/barney/emptystate.rb
55
- - lib/barney/jobs.rb
56
- - lib/barney/share.rb
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - barney.gemspec
57
57
  - lib/barney.rb
58
- - test/suite/lib/barney/jobs.rb
58
+ - lib/barney/core_ext/barney.rb
59
+ - lib/barney/core_ext/jobs.rb
60
+ - lib/barney/methodlookup.rb
61
+ - lib/barney/share.rb
62
+ - samples/barney_method_sample.rb
63
+ - samples/jobs_method_sample.rb
64
+ - test/helpers/methodscopetest.rb
65
+ - test/helpers/selfscopetest.rb
66
+ - test/setup.rb
67
+ - test/suite/lib/barney/core_ext/barney.rb
68
+ - test/suite/lib/barney/core_ext/jobs.rb
59
69
  - test/suite/lib/barney/share#fork.rb
60
70
  - test/suite/lib/barney/share#history.rb
61
71
  - test/suite/lib/barney/share#initialize.rb
62
72
  - test/suite/lib/barney/share#shared.rb
63
73
  - test/suite/lib/barney/share#synchronize.rb
64
74
  - test/suite/lib/barney/share#unshare.rb
65
- - test/suite/lib/barney.rb
75
+ - test/suite/misc/warnings.rb
66
76
  has_rdoc: true
67
77
  homepage: http://github.com/robgleeson/barney
68
78
  licenses: []
@@ -92,11 +102,15 @@ signing_key:
92
102
  specification_version: 3
93
103
  summary: Barney tries to make the sharing of data between processes as easy and natural as possible.
94
104
  test_files:
95
- - test/suite/lib/barney/jobs.rb
105
+ - test/helpers/methodscopetest.rb
106
+ - test/helpers/selfscopetest.rb
107
+ - test/setup.rb
108
+ - test/suite/lib/barney/core_ext/barney.rb
109
+ - test/suite/lib/barney/core_ext/jobs.rb
96
110
  - test/suite/lib/barney/share#fork.rb
97
111
  - test/suite/lib/barney/share#history.rb
98
112
  - test/suite/lib/barney/share#initialize.rb
99
113
  - test/suite/lib/barney/share#shared.rb
100
114
  - test/suite/lib/barney/share#synchronize.rb
101
115
  - test/suite/lib/barney/share#unshare.rb
102
- - test/suite/lib/barney.rb
116
+ - test/suite/misc/warnings.rb
data/LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (C) 2011 by Robert Gleeson
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to deal
5
- in the Software without restriction, including without limitation the rights
6
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- copies of the Software, and to permit persons to whom the Software is
8
- furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
20
-
@@ -1,26 +0,0 @@
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
-
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # Magic "Barney" method
4
-
5
- require 'barney'
6
-
7
- name = 'Robert'
8
-
9
- Barney do
10
- share :name
11
-
12
- fork do
13
- name.slice! 3..5
14
- end
15
- end
16
-
17
- p name # "Rob"
@@ -1,26 +0,0 @@
1
- describe 'Barney' do
2
-
3
- it 'should respond to all Barney::Share methods.' do
4
- methods = Barney::Share.instance_methods false
5
- methods.each do |meth|
6
- assert Barney.respond_to?(meth.to_sym), "Barney should respond to #{meth}"
7
- end
8
- end
9
-
10
- end
11
-
12
- describe '#Barney' do
13
-
14
- it 'should synchronize data using the #Barney() method.' 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
@@ -1,9 +0,0 @@
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