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 +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +5 -0
- data/README.md +3 -1
- data/examples/basics.rb +2 -2
- data/examples/composing.rb +2 -2
- data/lib/datapipes.rb +32 -12
- data/lib/datapipes/pipe.rb +5 -5
- data/lib/datapipes/source.rb +1 -1
- data/lib/datapipes/version.rb +1 -1
- data/spec/basics_spec.rb +2 -2
- data/spec/composing_spec.rb +2 -2
- data/spec/intact_spec.rb +11 -0
- data/spec/spec_helper.rb +5 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1863bd8ffe4af8833093199f29b332f3911067c9
|
4
|
+
data.tar.gz: df0e6af9d83caa8fdb684d32c16bcd314d35fa51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62eb3d70c73d90635e49100cd2153803dc8642419a8c94f32b87e6c59eb994c04b1bce2a0d96312900f103945db36364740a6128498541a71d32b84d6231b600
|
7
|
+
data.tar.gz: 14f92a41066e77e14087378e53c62834540383bfebef660d69bd53491210f1112e2b02e8e6a62a7c33e1218a40c5b0dcb2e886860d6ad4e6b10d07fde5795085
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
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
|
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
|
|
data/examples/basics.rb
CHANGED
data/examples/composing.rb
CHANGED
data/lib/datapipes.rb
CHANGED
@@ -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
|
-
#
|
16
|
-
#
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
43
|
+
sink = run_sink
|
34
44
|
runners.each(&:join)
|
35
45
|
|
36
46
|
notify_resource_ending
|
37
|
-
|
47
|
+
sink.join
|
38
48
|
end
|
39
49
|
|
40
50
|
private
|
41
51
|
|
42
|
-
def
|
52
|
+
def run_sink
|
43
53
|
Thread.new do
|
44
54
|
loop do
|
45
|
-
data = @pipe.
|
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.
|
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
|
data/lib/datapipes/pipe.rb
CHANGED
@@ -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
|
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
|
19
|
+
def pour_in(data)
|
20
20
|
@queue.enq data
|
21
21
|
end
|
22
22
|
|
23
|
-
#
|
24
|
-
def
|
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
|
data/lib/datapipes/source.rb
CHANGED
data/lib/datapipes/version.rb
CHANGED
data/spec/basics_spec.rb
CHANGED
data/spec/composing_spec.rb
CHANGED
data/spec/intact_spec.rb
ADDED
data/spec/spec_helper.rb
CHANGED
@@ -4,9 +4,13 @@ require 'stringio'
|
|
4
4
|
require 'coveralls'
|
5
5
|
require 'simplecov'
|
6
6
|
Coveralls.wear!
|
7
|
-
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
|
+
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-
|
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
|