datapipes 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8abb0451500188b58038dbb2731ff2fcb8977f4b
4
- data.tar.gz: 7f6348febf36db66e7939bca687b820f5a029fe4
3
+ metadata.gz: 1863bd8ffe4af8833093199f29b332f3911067c9
4
+ data.tar.gz: df0e6af9d83caa8fdb684d32c16bcd314d35fa51
5
5
  SHA512:
6
- metadata.gz: 43ba18b6df1af0b1118ac7c39c719d0f7d63160cd90247e1e2a0b4dd8baf3992a888fede632491d7f276b949b07910f327f761758f719e4ff36604626e3db385
7
- data.tar.gz: 413545e4c611a78e48f98ce0cfb791003b7ae9512b16adee0535159e49cd30368c81b6a2671e7bc62179cd1ae52984de6ebd1846a31a2b9f1973aa90faeb4a6f
6
+ metadata.gz: 62eb3d70c73d90635e49100cd2153803dc8642419a8c94f32b87e6c59eb994c04b1bce2a0d96312900f103945db36364740a6128498541a71d32b84d6231b600
7
+ data.tar.gz: 14f92a41066e77e14087378e53c62834540383bfebef660d69bd53491210f1112e2b02e8e6a62a7c33e1218a40c5b0dcb2e886860d6ad4e6b10d07fde5795085
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .ruby-version
@@ -2,6 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - 2.1
4
4
  - 2.0
5
+ - 1.9.3
5
6
  branches:
6
7
  only:
7
8
  - master
@@ -1,3 +1,8 @@
1
+ ## 0.1.5
2
+ - Change Pipe API name: recieve -> pour_in, pull -> pour_out
3
+ - Change Datapipes.new API: all arguments must be given as a Hash.
4
+ - Revival Ruby 1.9.3 supports.
5
+
1
6
  ## 0.1.4
2
7
  - Add documents.
3
8
 
data/README.md CHANGED
@@ -23,7 +23,7 @@ a few objects sparated by its responsibility.
23
23
  Sink
24
24
  ```
25
25
 
26
- To handle multi streamings, datapipes offers composabiliy. Source, Tube and Sink
26
+ To handle multi streamings, datapipes offers composability. Source, Tube and Sink
27
27
  are composable individually. So the diagram above will be:
28
28
 
29
29
  ```
@@ -45,6 +45,8 @@ are composable individually. So the diagram above will be:
45
45
  Composed Sink works concurrently.
46
46
  ```
47
47
 
48
+ You can see how to compose objects in `examples/composing.rb`.
49
+
48
50
  ## Installation
49
51
  __datapipes requires Ruby >= 2.0.__
50
52
 
@@ -10,8 +10,8 @@ require 'print'
10
10
  # Then you can make your own datapipe with your objects.
11
11
  #
12
12
  datapipe = Datapipes.new(
13
- List.new, # A source
14
- Print.new, # A sink
13
+ source: List.new,
14
+ sink: Print.new,
15
15
  tube: Triple.new,
16
16
  )
17
17
 
@@ -16,8 +16,8 @@ tube = Mul.new >> Triple.new
16
16
  sink = acc + rev_acc
17
17
 
18
18
  datapipe = Datapipes.new(
19
- source,
20
- sink,
19
+ source: source,
20
+ sink: sink,
21
21
  tube: tube
22
22
  )
23
23
 
@@ -12,13 +12,23 @@ class Datapipes
12
12
  # Pass datapipes components instances.
13
13
  # Each component can be composed. See detail in examples.
14
14
  #
15
- # tube and pipe are optional.
16
- # If not given tube, a default tube which takes no effect is used.
17
- def initialize(source, sink, tube: Tube.new, pipe: Pipe.new)
18
- @source = source
19
- @tube = tube
20
- @sink = sink
21
- @pipe = pipe
15
+ # Pass parameters as a hash:
16
+ #
17
+ # datapipe = Datapipes.new(source: my_source, sink: my_sink)
18
+ #
19
+ # Or pass all:
20
+ #
21
+ # datapipe = Datapipes.new(
22
+ # source: my_source,
23
+ # sink: my_sink,
24
+ # tube: my_tube,
25
+ # pipe: my_pipe
26
+ # )
27
+ #
28
+ # All arguments are optional. But in most case, you specify
29
+ # source and sink.
30
+ def initialize(args = {})
31
+ @source, @sink, @tube, @pipe = *ArgParser.extract(args)
22
32
  end
23
33
 
24
34
  # Run sources, data flow via pipe, tubes and sinks work.
@@ -30,19 +40,19 @@ class Datapipes
30
40
  @source.pipe = @pipe
31
41
  runners = @source.run_all
32
42
 
33
- consumer = run_comsumer
43
+ sink = run_sink
34
44
  runners.each(&:join)
35
45
 
36
46
  notify_resource_ending
37
- consumer.join
47
+ sink.join
38
48
  end
39
49
 
40
50
  private
41
51
 
42
- def run_comsumer
52
+ def run_sink
43
53
  Thread.new do
44
54
  loop do
45
- data = @pipe.pull
55
+ data = @pipe.pour_out
46
56
  break if resource_ended?(data)
47
57
 
48
58
  @sink.run_all(@tube.run(data))
@@ -51,7 +61,7 @@ class Datapipes
51
61
  end
52
62
 
53
63
  def notify_resource_ending
54
- @pipe.recieve Notification.new
64
+ @pipe.pour_in Notification.new
55
65
  end
56
66
 
57
67
  def resource_ended?(data)
@@ -59,4 +69,14 @@ class Datapipes
59
69
  end
60
70
 
61
71
  Notification = Class.new
72
+
73
+ module ArgParser
74
+ def self.extract(args)
75
+ source = args[:source] || Source.new
76
+ sink = args[:sink] || Sink.new
77
+ tube = args[:tube] || Tube.new
78
+ pipe = args[:pipe] || Pipe.new
79
+ [source, sink, tube, pipe]
80
+ end
81
+ end
62
82
  end
@@ -7,8 +7,8 @@ class Datapipes
7
7
  # If you make your own, you can override _initialize_, because
8
8
  # this is not used in internal.
9
9
  #
10
- # Then supply _recieve_ and _pull_. _pull_ must cause thread blocking
11
- # when it is empty.
10
+ # Then supply _pour_in_ and _pour_out_. _pour_out_ must occur
11
+ # thread blocking when it is empty.
12
12
  class Pipe
13
13
  # You can override and don't need to call super in sub class.
14
14
  def initialize
@@ -16,12 +16,12 @@ class Datapipes
16
16
  end
17
17
 
18
18
  # Emit data to pipe.
19
- def recieve(data)
19
+ def pour_in(data)
20
20
  @queue.enq data
21
21
  end
22
22
 
23
- # _pull_ must cause thread blocking when it is empty.
24
- def pull
23
+ # _pour_out_ must cause thread blocking when it is empty.
24
+ def pour_out
25
25
  @queue.deq
26
26
  end
27
27
  end
@@ -37,7 +37,7 @@ class Datapipes
37
37
  private
38
38
 
39
39
  def produce(data)
40
- @pipe.recieve(data)
40
+ @pipe.pour_in(data)
41
41
  end
42
42
 
43
43
  def set_pipe
@@ -1,3 +1,3 @@
1
1
  class Datapipes
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
@@ -11,8 +11,8 @@ describe 'basic function' do
11
11
 
12
12
  let(:datapipe) do
13
13
  Datapipes.new(
14
- List.new,
15
- Print.new,
14
+ source: List.new,
15
+ sink: Print.new,
16
16
  tube: Triple.new
17
17
  )
18
18
  end
@@ -18,8 +18,8 @@ describe 'composability' do
18
18
 
19
19
  let(:datapipe) do
20
20
  Datapipes.new(
21
- source,
22
- sink,
21
+ source: source,
22
+ sink: sink,
23
23
  tube: tube
24
24
  )
25
25
  end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'intact objects' do
4
+ let(:datapipe) do
5
+ Datapipes.new
6
+ end
7
+
8
+ it 'runs but occurs nothing' do
9
+ expect { datapipe.run_resource }.not_to raise_error
10
+ end
11
+ end
@@ -4,9 +4,13 @@ require 'stringio'
4
4
  require 'coveralls'
5
5
  require 'simplecov'
6
6
  Coveralls.wear!
7
- SimpleCov.formatter = Coveralls::SimpleCov::Formatter
7
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
+ SimpleCov::Formatter::HTMLFormatter,
9
+ Coveralls::SimpleCov::Formatter
10
+ ]
8
11
  SimpleCov.start do
9
12
  add_filter 'spec'
13
+ add_filter 'examples'
10
14
  end
11
15
 
12
16
  $: << File.expand_path('../../lib', __FILE__)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datapipes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taiki ONO
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-06 00:00:00.000000000 Z
11
+ date: 2014-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parallel
@@ -143,6 +143,7 @@ files:
143
143
  - lib/datapipes/version.rb
144
144
  - spec/basics_spec.rb
145
145
  - spec/composing_spec.rb
146
+ - spec/intact_spec.rb
146
147
  - spec/sink_spec.rb
147
148
  - spec/spec_helper.rb
148
149
  - spec/tube_spec.rb
@@ -173,6 +174,7 @@ summary: An asynchronous multi steamings library.
173
174
  test_files:
174
175
  - spec/basics_spec.rb
175
176
  - spec/composing_spec.rb
177
+ - spec/intact_spec.rb
176
178
  - spec/sink_spec.rb
177
179
  - spec/spec_helper.rb
178
180
  - spec/tube_spec.rb