datapipes 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/CHANGELOG.md +3 -0
- data/README.md +4 -80
- data/datapipes.gemspec +2 -0
- data/examples/basics.rb +22 -3
- data/examples/composing.rb +24 -0
- data/examples/lib/acc.rb +14 -0
- data/examples/lib/list.rb +8 -0
- data/examples/lib/long_task.rb +11 -0
- data/examples/lib/mul.rb +13 -0
- data/examples/{print.rb → lib/print.rb} +2 -0
- data/examples/{triple.rb → lib/triple.rb} +3 -0
- data/lib/datapipes/pipe.rb +0 -8
- data/lib/datapipes/sink.rb +1 -1
- data/lib/datapipes/source.rb +6 -1
- data/lib/datapipes/version.rb +1 -1
- data/spec/basics_spec.rb +1 -1
- data/spec/composing_spec.rb +27 -0
- data/spec/spec_helper.rb +8 -0
- metadata +40 -7
- data/examples/list.rb +0 -5
- data/spec/composable_spec.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a09f50e26a2e9da8b66f7bd6904a78e451a8a78a
|
4
|
+
data.tar.gz: 047393dea516f11e7de3ccac83b9a936cd84ed50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2e0b92e8f32a6b45e711d9f129255046b02089e27fbd43370b4e4272e85e50da209b5b4596ad9750bb034dfb424680b0fc6c12098724c3ca991489789646c0e
|
7
|
+
data.tar.gz: aac12fc41369a05128f0bfbfb3e07ad3b4cc95dd450f89d396e5aeaa303da53283ccd4aa65e0d4b42b0b0cc5e8a315e4e2f5a4062bd60746881612f50a8f2010
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
datapipes [![
|
1
|
+
datapipes [![Gem Version](https://badge.fury.io/rb/datapipes.svg)](http://badge.fury.io/rb/datapipes)
|
2
2
|
=========
|
3
3
|
datapipes is an asynchronous multi streaming library.
|
4
4
|
|
5
|
+
[![Build Status](https://travis-ci.org/taiki45/datapipes.svg?branch=master)](https://travis-ci.org/taiki45/datapipes) [![Coverage Status](https://coveralls.io/repos/taiki45/datapipes/badge.png?branch=master)](https://coveralls.io/r/taiki45/datapipes?branch=master) [![Code Climate](https://codeclimate.com/github/taiki45/datapipes.png)](https://codeclimate.com/github/taiki45/datapipes) [![Dependency Status](https://gemnasium.com/taiki45/datapipes.svg)](https://gemnasium.com/taiki45/datapipes) [![Inline docs](http://inch-pages.github.io/github/taiki45/datapipes.png)](http://inch-pages.github.io/github/taiki45/datapipes)
|
6
|
+
|
5
7
|
## About
|
6
8
|
datapipes encourages to handle multi streamings asynchronously. datapipes has
|
7
9
|
a few objects sparated by its responsibility.
|
@@ -58,85 +60,7 @@ Or install it yourself as:
|
|
58
60
|
$ gem install datapipes
|
59
61
|
|
60
62
|
## Usage
|
61
|
-
You have to define your own Source, Tube and Sink.
|
62
|
-
|
63
|
-
A basic source is list type. it produces a value in several times.
|
64
|
-
Use `produce` method to emit data to pipe.
|
65
|
-
|
66
|
-
```ruby
|
67
|
-
class List < Datapipes::Source
|
68
|
-
def run
|
69
|
-
(1..10).each {|i| produce(i) }
|
70
|
-
end
|
71
|
-
end
|
72
|
-
```
|
73
|
-
|
74
|
-
Next is tube. Tube processes piped data. A example tube recieve
|
75
|
-
Integer value then increase amount of the value.
|
76
|
-
|
77
|
-
Define `accept?` to recieve the data or skip this.
|
78
|
-
|
79
|
-
```ruby
|
80
|
-
class Triple < Datapipes::Tube
|
81
|
-
def run(data)
|
82
|
-
if accept? data
|
83
|
-
[data, data, data]
|
84
|
-
else
|
85
|
-
data
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def accept?(data)
|
90
|
-
data.is_a? Integer and data > 3
|
91
|
-
end
|
92
|
-
end
|
93
|
-
```
|
94
|
-
|
95
|
-
Sink consumes piped data. A typical sink is printing data.
|
96
|
-
|
97
|
-
```ruby
|
98
|
-
class Print < Datapipes::Sink
|
99
|
-
def run(data)
|
100
|
-
puts data if accept? data
|
101
|
-
end
|
102
|
-
|
103
|
-
def accept?(data)
|
104
|
-
data.is_a? Array and data[0] < 7
|
105
|
-
end
|
106
|
-
end
|
107
|
-
```
|
108
|
-
|
109
|
-
You can make your own datapipe with your objects.
|
110
|
-
|
111
|
-
```ruby
|
112
|
-
datapipe = Datapipes.new(
|
113
|
-
List.new, # A source
|
114
|
-
Print.new, # A sink
|
115
|
-
tube: Triple.new,
|
116
|
-
)
|
117
|
-
```
|
118
|
-
|
119
|
-
Then just run everything with `run_resource`.
|
120
|
-
|
121
|
-
```ruby
|
122
|
-
datapipe.run_resource
|
123
|
-
```
|
124
|
-
|
125
|
-
The output will be:
|
126
|
-
|
127
|
-
```
|
128
|
-
4
|
129
|
-
4
|
130
|
-
4
|
131
|
-
5
|
132
|
-
5
|
133
|
-
5
|
134
|
-
6
|
135
|
-
6
|
136
|
-
6
|
137
|
-
```
|
138
|
-
|
139
|
-
Congratulation!!
|
63
|
+
You have to define your own Source, Tube and Sink. See more in `examples`.
|
140
64
|
|
141
65
|
### Composing objects
|
142
66
|
TODO...
|
data/datapipes.gemspec
CHANGED
@@ -23,4 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency 'rake'
|
24
24
|
spec.add_development_dependency 'rspec'
|
25
25
|
spec.add_development_dependency 'pry'
|
26
|
+
spec.add_development_dependency 'simplecov', '~> 0.8'
|
27
|
+
spec.add_development_dependency 'coveralls', '~> 0.7'
|
26
28
|
end
|
data/examples/basics.rb
CHANGED
@@ -1,14 +1,33 @@
|
|
1
1
|
require 'datapipes'
|
2
|
-
|
3
|
-
|
2
|
+
#
|
3
|
+
# You have to define your own Source, Tube and Sink.
|
4
|
+
#
|
5
|
+
$: << File.expand_path('../lib', __FILE__)
|
4
6
|
require 'list'
|
5
7
|
require 'triple'
|
6
8
|
require 'print'
|
7
|
-
|
9
|
+
#
|
10
|
+
# Then you can make your own datapipe with your objects.
|
11
|
+
#
|
8
12
|
datapipe = Datapipes.new(
|
9
13
|
List.new, # A source
|
10
14
|
Print.new, # A sink
|
11
15
|
tube: Triple.new,
|
12
16
|
)
|
13
17
|
|
18
|
+
# Just run everything with `run_resource`.
|
14
19
|
datapipe.run_resource
|
20
|
+
|
21
|
+
# The output will be:
|
22
|
+
#
|
23
|
+
# 4
|
24
|
+
# 4
|
25
|
+
# 4
|
26
|
+
# 5
|
27
|
+
# 5
|
28
|
+
# 5
|
29
|
+
# 6
|
30
|
+
# 6
|
31
|
+
# 6
|
32
|
+
#
|
33
|
+
# Congratulation!!
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'datapipes'
|
2
|
+
|
3
|
+
$: << File.expand_path('../lib', __FILE__)
|
4
|
+
require 'list'
|
5
|
+
require 'long_task'
|
6
|
+
require 'mul'
|
7
|
+
require 'triple'
|
8
|
+
require 'acc'
|
9
|
+
|
10
|
+
acc = Acc.new
|
11
|
+
|
12
|
+
source = List.new + LongTask.new(21..30)
|
13
|
+
tube = Mul.new >> Triple.new
|
14
|
+
sink = acc
|
15
|
+
|
16
|
+
datapipe = Datapipes.new(
|
17
|
+
source,
|
18
|
+
sink,
|
19
|
+
tube: tube
|
20
|
+
)
|
21
|
+
|
22
|
+
datapipe.run_resource
|
23
|
+
|
24
|
+
p acc.stock
|
data/examples/lib/acc.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# A sink is never called concurrently.
|
2
|
+
# On the other side, each sink can be called concurrently.
|
3
|
+
# So be careful to occur race condition in multi sinks.
|
4
|
+
class Acc < Datapipes::Sink
|
5
|
+
attr_reader :stock
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@stock = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def run(data)
|
12
|
+
@stock << data
|
13
|
+
end
|
14
|
+
end
|
data/examples/lib/mul.rb
ADDED
data/lib/datapipes/pipe.rb
CHANGED
data/lib/datapipes/sink.rb
CHANGED
data/lib/datapipes/source.rb
CHANGED
@@ -14,13 +14,18 @@ class Datapipes
|
|
14
14
|
|
15
15
|
def run_all
|
16
16
|
@accumulated ||= [self]
|
17
|
+
set_pipe
|
17
18
|
@accumulated.map {|s| Thread.new { s.run } }
|
18
19
|
end
|
19
20
|
|
20
21
|
private
|
21
22
|
|
22
23
|
def produce(data)
|
23
|
-
pipe.recieve(data)
|
24
|
+
@pipe.recieve(data)
|
25
|
+
end
|
26
|
+
|
27
|
+
def set_pipe
|
28
|
+
@accumulated.each {|s| s.pipe = @pipe }
|
24
29
|
end
|
25
30
|
end
|
26
31
|
end
|
data/lib/datapipes/version.rb
CHANGED
data/spec/basics_spec.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
$: << File.expand_path('../../examples/lib', __FILE__)
|
4
|
+
require 'list'
|
5
|
+
require 'long_task'
|
6
|
+
require 'mul'
|
7
|
+
require 'triple'
|
8
|
+
require 'acc'
|
9
|
+
|
10
|
+
describe 'composability' do
|
11
|
+
let(:acc) { Acc.new }
|
12
|
+
let(:source) { List.new + LongTask.new(21..30) }
|
13
|
+
let(:tube) { Mul.new >> Triple.new }
|
14
|
+
|
15
|
+
let(:datapipe) do
|
16
|
+
Datapipes.new(
|
17
|
+
source,
|
18
|
+
acc,
|
19
|
+
tube: tube
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'runs without errors' do
|
24
|
+
datapipe.run_resource
|
25
|
+
expect(acc.stock).to have(20).items
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
require 'pry'
|
2
2
|
require 'stringio'
|
3
3
|
|
4
|
+
require 'coveralls'
|
5
|
+
require 'simplecov'
|
6
|
+
Coveralls.wear!
|
7
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
8
|
+
SimpleCov.start do
|
9
|
+
add_filter 'spec'
|
10
|
+
end
|
11
|
+
|
4
12
|
$: << File.expand_path('../../lib', __FILE__)
|
5
13
|
require 'datapipes'
|
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.3
|
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-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parallel
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.8'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.8'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: coveralls
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.7'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.7'
|
83
111
|
description: To handle multi steamings easily.
|
84
112
|
email:
|
85
113
|
- taiks.4559@gmail.com
|
@@ -87,6 +115,7 @@ executables: []
|
|
87
115
|
extensions: []
|
88
116
|
extra_rdoc_files: []
|
89
117
|
files:
|
118
|
+
- ".coveralls.yml"
|
90
119
|
- ".gitignore"
|
91
120
|
- ".rspec"
|
92
121
|
- ".travis.yml"
|
@@ -97,9 +126,13 @@ files:
|
|
97
126
|
- Rakefile
|
98
127
|
- datapipes.gemspec
|
99
128
|
- examples/basics.rb
|
100
|
-
- examples/
|
101
|
-
- examples/
|
102
|
-
- examples/
|
129
|
+
- examples/composing.rb
|
130
|
+
- examples/lib/acc.rb
|
131
|
+
- examples/lib/list.rb
|
132
|
+
- examples/lib/long_task.rb
|
133
|
+
- examples/lib/mul.rb
|
134
|
+
- examples/lib/print.rb
|
135
|
+
- examples/lib/triple.rb
|
103
136
|
- lib/datapipes.rb
|
104
137
|
- lib/datapipes/composable.rb
|
105
138
|
- lib/datapipes/pipe.rb
|
@@ -108,7 +141,7 @@ files:
|
|
108
141
|
- lib/datapipes/tube.rb
|
109
142
|
- lib/datapipes/version.rb
|
110
143
|
- spec/basics_spec.rb
|
111
|
-
- spec/
|
144
|
+
- spec/composing_spec.rb
|
112
145
|
- spec/sink_spec.rb
|
113
146
|
- spec/spec_helper.rb
|
114
147
|
- spec/tube_spec.rb
|
@@ -138,7 +171,7 @@ specification_version: 4
|
|
138
171
|
summary: An asynchronous multi steamings library.
|
139
172
|
test_files:
|
140
173
|
- spec/basics_spec.rb
|
141
|
-
- spec/
|
174
|
+
- spec/composing_spec.rb
|
142
175
|
- spec/sink_spec.rb
|
143
176
|
- spec/spec_helper.rb
|
144
177
|
- spec/tube_spec.rb
|
data/examples/list.rb
DELETED
data/spec/composable_spec.rb
DELETED