datapipes 0.1.0 → 0.1.1

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: 36fcf4de0a57bf1712ee266c6d99272ae5b823bf
4
- data.tar.gz: 3c88fe0667cf777f8241cbf57c4f729046645092
3
+ metadata.gz: e7320f603074b6f0907667850275091622de079d
4
+ data.tar.gz: f5c9b51dac1c2c63f7b8703ea7144eaecf5cee85
5
5
  SHA512:
6
- metadata.gz: d79a8457b86cbc3f9e12128e7e08ef840d7e90fd9f230cc57c48e41b7997570dfec5865c60ee0256ccfc511cc2e6a985dda7038821379d59fd61863e17fb1c6f
7
- data.tar.gz: 0a5a5a692c50f1814affee9caaf132e0c142951733147d7683c02ba83daa3db5c4ec0e4d13d2c74449408438293b5d8b410628856eac37aec4afd5cd83c2f0f4
6
+ metadata.gz: 0b98bee8388e04ff8f841e9d9cd5f9f07fc3faaed18d2513630cb38b060fc2e9f9d46b64373d6275af06c657ba80891512ef32ea58d86111f907718a6c3ddf1e
7
+ data.tar.gz: fdcd53dcc0be76ac8603bcf58a265753d496a60f0d45e5befef68a592a5cd4adf6957453134bc949dfb7123a083e5ab9617a97c97f0da92d2076b60797ba8937
@@ -2,7 +2,6 @@ language: ruby
2
2
  rvm:
3
3
  - 2.1
4
4
  - 2.0
5
- - 1.9.3
6
5
  branches:
7
6
  only:
8
7
  - master
@@ -1,3 +1,7 @@
1
+ ## 0.1.1
2
+ - Drop Ruby 1.9 supports.
3
+ - Tube and Pipe are optional in making datapipe.
4
+
1
5
  ## 0.1.0
2
6
  - Change Tube cmposing way. https://github.com/taiki45/datapipes/pull/4
3
7
  - Remove `accept?` methods from Tube and Sink. d966744f9
@@ -1,36 +1,14 @@
1
1
  require 'datapipes'
2
2
 
3
- class List < Datapipes::Source
4
- def run
5
- (1..10).each {|i| produce(i) }
6
- end
7
- end
8
-
9
- class Triple < Datapipes::Tube
10
- def run(data)
11
- [data, data, data]
12
- end
13
-
14
- def accept?(data)
15
- data.is_a? Integer and data > 3
16
- end
17
- end
18
-
19
- class Print < Datapipes::Sink
20
- def run(data)
21
- puts data
22
- end
23
-
24
- def accept?(data)
25
- data.is_a? Array and data[0] < 7
26
- end
27
- end
3
+ $: << File.expand_path('..', __FILE__)
4
+ require 'list'
5
+ require 'triple'
6
+ require 'print'
28
7
 
29
8
  datapipe = Datapipes.new(
30
- List.new, # A source
31
- Triple.new, # A tube
32
- Print.new, # A sink
33
- Datapipes::Pipe.new # A pipe
9
+ List.new, # A source
10
+ Print.new, # A sink
11
+ tube: Triple.new,
34
12
  )
35
13
 
36
14
  datapipe.run_resource
@@ -0,0 +1,5 @@
1
+ class List < Datapipes::Source
2
+ def run
3
+ (1..10).each {|i| produce(i) }
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ class Print < Datapipes::Sink
2
+ def run(data)
3
+ puts data if accept? data
4
+ end
5
+
6
+ def accept?(data)
7
+ data.is_a? Array and data[0] < 7
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ class Triple < Datapipes::Tube
2
+ def run(data)
3
+ if accept? data
4
+ [data, data, data]
5
+ else
6
+ data
7
+ end
8
+ end
9
+
10
+ def accept?(data)
11
+ data.is_a? Integer and data > 3
12
+ end
13
+ end
@@ -5,16 +5,14 @@ require 'datapipes/sink'
5
5
  require 'datapipes/pipe'
6
6
  require 'datapipes/version'
7
7
 
8
+ Thread.abort_on_exception = true
9
+
8
10
  class Datapipes
9
- # TODO: optional tube and pipe
10
- def initialize(source, tube, sink, pipe)
11
+ def initialize(source, sink, tube: Tube.new, pipe: Pipe.new)
11
12
  @source = source
12
13
  @tube = tube
13
14
  @sink = sink
14
15
  @pipe = pipe
15
-
16
- Thread.abort_on_exception = true
17
- @flag = Queue.new
18
16
  end
19
17
 
20
18
  def run_resource
@@ -25,7 +23,7 @@ class Datapipes
25
23
  runners.each(&:join)
26
24
 
27
25
  notify_resource_ending
28
- graceful_down(consumer)
26
+ consumer.join
29
27
  end
30
28
 
31
29
  private
@@ -33,27 +31,21 @@ class Datapipes
33
31
  def run_comsumer
34
32
  Thread.new do
35
33
  loop do
36
- break if resource_ended? && @pipe.empty?
34
+ data = @pipe.pull
35
+ break if resource_ended?(data)
37
36
 
38
- data = @tube.run(@pipe.pull)
39
- @sink.run_all(data)
37
+ @sink.run_all(@tube.run(data))
40
38
  end
41
- Thread.current.kill
42
39
  end
43
40
  end
44
41
 
45
42
  def notify_resource_ending
46
- @flag.enq true
47
- Thread.pass
43
+ @pipe.recieve Notification.new
48
44
  end
49
45
 
50
- def resource_ended?
51
- !@flag.empty?
46
+ def resource_ended?(data)
47
+ data.is_a? Notification
52
48
  end
53
49
 
54
- def graceful_down(consumer)
55
- sleep 0.1
56
- consumer.kill if consumer.status == 'sleep'
57
- consumer.join
58
- end
50
+ Notification = Class.new
59
51
  end
@@ -1,3 +1,3 @@
1
1
  class Datapipes
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -1,16 +1,19 @@
1
1
  require 'spec_helper'
2
- require 'datapipes/basics'
3
2
 
4
- describe Datapipes::Basics do
3
+ $: << File.expand_path('../../examples', __FILE__)
4
+ require 'list'
5
+ require 'triple'
6
+ require 'print'
7
+
8
+ describe 'basic function' do
5
9
  before { $stdout = StringIO.new }
6
10
  after { $stdout = STDOUT }
7
11
 
8
12
  let(:datapipe) do
9
13
  Datapipes.new(
10
- Datapipes::Basics::List.new,
11
- Datapipes::Basics::Triple.new,
12
- Datapipes::Basics::Print.new,
13
- Datapipes::Pipe.new
14
+ List.new,
15
+ Print.new,
16
+ tube: Triple.new
14
17
  )
15
18
  end
16
19
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datapipes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taiki ONO
@@ -83,11 +83,10 @@ files:
83
83
  - Rakefile
84
84
  - datapipes.gemspec
85
85
  - examples/basics.rb
86
+ - examples/list.rb
87
+ - examples/print.rb
88
+ - examples/triple.rb
86
89
  - lib/datapipes.rb
87
- - lib/datapipes/basics.rb
88
- - lib/datapipes/basics/list.rb
89
- - lib/datapipes/basics/print.rb
90
- - lib/datapipes/basics/triple.rb
91
90
  - lib/datapipes/composable.rb
92
91
  - lib/datapipes/pipe.rb
93
92
  - lib/datapipes/sink.rb
@@ -1,3 +0,0 @@
1
- require 'datapipes/basics/list'
2
- require 'datapipes/basics/triple'
3
- require 'datapipes/basics/print'
@@ -1,9 +0,0 @@
1
- class Datapipes
2
- module Basics
3
- class List < Source
4
- def run
5
- (1..10).each {|i| produce(i) }
6
- end
7
- end
8
- end
9
- end
@@ -1,13 +0,0 @@
1
- class Datapipes
2
- module Basics
3
- class Print < Sink
4
- def run(data)
5
- puts data if accept? data
6
- end
7
-
8
- def accept?(data)
9
- data.is_a? Array and data[0] < 7
10
- end
11
- end
12
- end
13
- end
@@ -1,17 +0,0 @@
1
- class Datapipes
2
- module Basics
3
- class Triple < Tube
4
- def run(data)
5
- if accept? data
6
- [data, data, data]
7
- else
8
- data
9
- end
10
- end
11
-
12
- def accept?(data)
13
- data.is_a? Integer and data > 3
14
- end
15
- end
16
- end
17
- end