datapipes 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ffc7cfd9159486b30bc40027879b31fcf40ab87c
4
- data.tar.gz: cf48ec612f2c42485caaee94d9699d1f5e55154d
3
+ metadata.gz: a09f50e26a2e9da8b66f7bd6904a78e451a8a78a
4
+ data.tar.gz: 047393dea516f11e7de3ccac83b9a936cd84ed50
5
5
  SHA512:
6
- metadata.gz: ccbbdcce3c53b5d31299a04416cd17949288e811c2cf5a6b86207af8f2e66ef4fec3e9695099aa280db55d68533a9a64400e3371a40fefca9af58fc6a0650174
7
- data.tar.gz: 1743f71987fdbc62052204ebb5ce7868330fd41893752858f13ec313a3af148ddbbd8b69cab1bc6e0eab53c7f5c3684432db2f6e45501635a929bc08c55669f5
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
@@ -1,3 +1,6 @@
1
+ ## 0.1.3
2
+ - Fix bug with composing sources.
3
+
1
4
  ## 0.1.2
2
5
  - Sinks runs in parallel.
3
6
 
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
- datapipes [![Build Status](https://travis-ci.org/taiki45/datapipes.svg?branch=master)](https://travis-ci.org/taiki45/datapipes) [![Gem Version](https://badge.fury.io/rb/datapipes.svg)](http://badge.fury.io/rb/datapipes) [![Code Climate](https://codeclimate.com/github/taiki45/datapipes.png)](https://codeclimate.com/github/taiki45/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
- $: << File.expand_path('..', __FILE__)
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
@@ -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
@@ -0,0 +1,8 @@
1
+ # A basic source is list type. it produces a value in several times.
2
+ # Use `produce` method to emit data to pipe.
3
+ #
4
+ class List < Datapipes::Source
5
+ def run
6
+ (1..10).each {|i| produce(i) }
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ class LongTask < Datapipes::Source
2
+ def initialize(range)
3
+ @range = range
4
+ end
5
+
6
+ def run
7
+ @range.each do |n|
8
+ produce n
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ class Mul < Datapipes::Tube
2
+ def run(data)
3
+ if match? data
4
+ data * 10
5
+ else
6
+ data
7
+ end
8
+ end
9
+
10
+ def match?(data)
11
+ data.is_a? Integer and data > 0
12
+ end
13
+ end
@@ -1,3 +1,5 @@
1
+ # Sink consumes piped data. A typical sink is printing data.
2
+ #
1
3
  class Print < Datapipes::Sink
2
4
  def run(data)
3
5
  puts data if accept? data
@@ -1,3 +1,6 @@
1
+ # Next is tube. Tube processes piped data. A example tube recieve
2
+ # Integer value then increase amount of the value.
3
+ #
1
4
  class Triple < Datapipes::Tube
2
5
  def run(data)
3
6
  if accept? data
@@ -11,13 +11,5 @@ class Datapipes
11
11
  def pull
12
12
  @queue.deq
13
13
  end
14
-
15
- def empty?
16
- @queue.empty?
17
- end
18
-
19
- def size
20
- @queue.size
21
- end
22
14
  end
23
15
  end
@@ -3,7 +3,7 @@ class Datapipes
3
3
  class Sink
4
4
  include Composable
5
5
 
6
- # TODO: parallel
6
+ # Run all sinks concurrently.
7
7
  def run_all(data)
8
8
  @accumulated ||= [self]
9
9
  count = Parallel.processor_count
@@ -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
@@ -1,3 +1,3 @@
1
1
  class Datapipes
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
data/spec/basics_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- $: << File.expand_path('../../examples', __FILE__)
3
+ $: << File.expand_path('../../examples/lib', __FILE__)
4
4
  require 'list'
5
5
  require 'triple'
6
6
  require 'print'
@@ -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.2
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-05 00:00:00.000000000 Z
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/list.rb
101
- - examples/print.rb
102
- - examples/triple.rb
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/composable_spec.rb
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/composable_spec.rb
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
@@ -1,5 +0,0 @@
1
- class List < Datapipes::Source
2
- def run
3
- (1..10).each {|i| produce(i) }
4
- end
5
- end
@@ -1,4 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Datapipes::Composable do
4
- end