datapipes 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/CHANGELOG.md +4 -0
- data/examples/basics.rb +7 -29
- data/examples/list.rb +5 -0
- data/examples/print.rb +9 -0
- data/examples/triple.rb +13 -0
- data/lib/datapipes.rb +11 -19
- data/lib/datapipes/version.rb +1 -1
- data/spec/basics_spec.rb +9 -6
- metadata +4 -5
- data/lib/datapipes/basics.rb +0 -3
- data/lib/datapipes/basics/list.rb +0 -9
- data/lib/datapipes/basics/print.rb +0 -13
- data/lib/datapipes/basics/triple.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7320f603074b6f0907667850275091622de079d
|
4
|
+
data.tar.gz: f5c9b51dac1c2c63f7b8703ea7144eaecf5cee85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b98bee8388e04ff8f841e9d9cd5f9f07fc3faaed18d2513630cb38b060fc2e9f9d46b64373d6275af06c657ba80891512ef32ea58d86111f907718a6c3ddf1e
|
7
|
+
data.tar.gz: fdcd53dcc0be76ac8603bcf58a265753d496a60f0d45e5befef68a592a5cd4adf6957453134bc949dfb7123a083e5ab9617a97c97f0da92d2076b60797ba8937
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/examples/basics.rb
CHANGED
@@ -1,36 +1,14 @@
|
|
1
1
|
require 'datapipes'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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,
|
31
|
-
|
32
|
-
|
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
|
data/examples/list.rb
ADDED
data/examples/print.rb
ADDED
data/examples/triple.rb
ADDED
data/lib/datapipes.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
34
|
+
data = @pipe.pull
|
35
|
+
break if resource_ended?(data)
|
37
36
|
|
38
|
-
|
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
|
-
@
|
47
|
-
Thread.pass
|
43
|
+
@pipe.recieve Notification.new
|
48
44
|
end
|
49
45
|
|
50
|
-
def resource_ended?
|
51
|
-
|
46
|
+
def resource_ended?(data)
|
47
|
+
data.is_a? Notification
|
52
48
|
end
|
53
49
|
|
54
|
-
|
55
|
-
sleep 0.1
|
56
|
-
consumer.kill if consumer.status == 'sleep'
|
57
|
-
consumer.join
|
58
|
-
end
|
50
|
+
Notification = Class.new
|
59
51
|
end
|
data/lib/datapipes/version.rb
CHANGED
data/spec/basics_spec.rb
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'datapipes/basics'
|
3
2
|
|
4
|
-
|
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
|
-
|
11
|
-
|
12
|
-
|
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.
|
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
|
data/lib/datapipes/basics.rb
DELETED