datapipes 0.0.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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/datapipes.gemspec +26 -0
- data/lib/datapipes/basics/list.rb +9 -0
- data/lib/datapipes/basics/print.rb +13 -0
- data/lib/datapipes/basics/triple.rb +13 -0
- data/lib/datapipes/basics.rb +3 -0
- data/lib/datapipes/composable.rb +11 -0
- data/lib/datapipes/pipe.rb +23 -0
- data/lib/datapipes/sink.rb +15 -0
- data/lib/datapipes/source.rb +26 -0
- data/lib/datapipes/tube.rb +22 -0
- data/lib/datapipes/version.rb +3 -0
- data/lib/datapipes.rb +52 -0
- data/spec/basics_spec.rb +25 -0
- data/spec/composable_spec.rb +45 -0
- data/spec/spec_helper.rb +5 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 923503ee040e215a0f4c3247aa522c5dad8556a2
|
4
|
+
data.tar.gz: 971f4a87d8ca50db1f26b2d053723184e5ab56c0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 35e1bd459e5398400f4aeb6b7f4a16d66f420c3e247a6bf53af93bbb11cdfdc875176d1a5f09bf7864185cfe99386b521568e4764f35f0687134abc65ac7bcda
|
7
|
+
data.tar.gz: fa6d68cabe35e231edad105596a3e9dba5fedf486ebe8d2cab9f5cf0c0cdf9c916221a05b1783a3e76105415525441acd1840d0005c3397233ccda87b0ee3f0b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Taiki ONO
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
datapipes
|
2
|
+
=========
|
3
|
+
datapipes is multi-streaming library.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'datapipes'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install datapipes
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/datapipes/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/datapipes.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'datapipes/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "datapipes"
|
8
|
+
spec.version = Datapipes::VERSION
|
9
|
+
spec.authors = ["Taiki ONO"]
|
10
|
+
spec.email = ["taiks.4559@gmail.com"]
|
11
|
+
spec.summary = %q{A library for processing steamings.}
|
12
|
+
spec.description = %q{A library for processing steamings.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'activesupport'
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "pry"
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Datapipes
|
2
|
+
class Pipe
|
3
|
+
def initialize
|
4
|
+
@queue ||= Queue.new
|
5
|
+
end
|
6
|
+
|
7
|
+
def recieve(data)
|
8
|
+
@queue.enq data
|
9
|
+
end
|
10
|
+
|
11
|
+
def pull
|
12
|
+
@queue.deq
|
13
|
+
end
|
14
|
+
|
15
|
+
def empty?
|
16
|
+
@queue.empty?
|
17
|
+
end
|
18
|
+
|
19
|
+
def size
|
20
|
+
@queue.size
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Datapipes
|
2
|
+
# Build your own sink logic in `run` method.
|
3
|
+
class Sink
|
4
|
+
include Composable
|
5
|
+
|
6
|
+
def run_all(data)
|
7
|
+
accumulated ||= [self]
|
8
|
+
accumulated.each {|sink| sink.run(data) if sink.accept? data }
|
9
|
+
end
|
10
|
+
|
11
|
+
def accept?(data)
|
12
|
+
true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Datapipes
|
2
|
+
#
|
3
|
+
# Build your own source logic in `run` method.
|
4
|
+
# Use `produce` method to emitt data to pipe.
|
5
|
+
#
|
6
|
+
# def run
|
7
|
+
# 10.times {|i| produce(i) }
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
class Source
|
11
|
+
include Composable
|
12
|
+
|
13
|
+
attr_accessor :pipe
|
14
|
+
|
15
|
+
def run_all
|
16
|
+
accumulated ||= [self]
|
17
|
+
accumulated.map {|s| Thread.new { s.run } }
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def produce(data)
|
23
|
+
pipe.recieve(data)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Datapipes
|
2
|
+
# Tube takes effect data which passes through pipe.
|
3
|
+
#
|
4
|
+
# Build your own tube logic in `run` method.
|
5
|
+
class Tube
|
6
|
+
def run_all(data)
|
7
|
+
accumulated ||= [self]
|
8
|
+
|
9
|
+
accumulated.reduce(data) do |d, tube|
|
10
|
+
if tube.accept? d
|
11
|
+
tube.run(d)
|
12
|
+
else
|
13
|
+
d
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def accept?(data)
|
19
|
+
true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/datapipes.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'active_support/all'
|
2
|
+
|
3
|
+
require 'datapipes/composable'
|
4
|
+
require 'datapipes/source'
|
5
|
+
require 'datapipes/tube'
|
6
|
+
require 'datapipes/sink'
|
7
|
+
require 'datapipes/pipe'
|
8
|
+
require 'datapipes/version'
|
9
|
+
|
10
|
+
class Datapipes
|
11
|
+
def initialize(source, tube, sink, pipe)
|
12
|
+
@source = source
|
13
|
+
@tube = tube
|
14
|
+
@sink = sink
|
15
|
+
@pipe = pipe
|
16
|
+
|
17
|
+
Thread.abort_on_exception = true
|
18
|
+
@flag = Queue.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def run_resource
|
22
|
+
@source.pipe = @pipe
|
23
|
+
runners = @source.run_all
|
24
|
+
|
25
|
+
consumer = run_comsumer
|
26
|
+
runners.each(&:join)
|
27
|
+
|
28
|
+
notify_resource_ending
|
29
|
+
consumer.join if consumer.status == "run"
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def run_comsumer
|
35
|
+
Thread.new do
|
36
|
+
loop do
|
37
|
+
break if resource_ended? && @pipe.empty?
|
38
|
+
|
39
|
+
data = @tube.run_all(@pipe.pull)
|
40
|
+
@sink.run_all(data)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def notify_resource_ending
|
46
|
+
@flag.enq true
|
47
|
+
end
|
48
|
+
|
49
|
+
def resource_ended?
|
50
|
+
!@flag.empty?
|
51
|
+
end
|
52
|
+
end
|
data/spec/basics_spec.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'datapipes/basics'
|
3
|
+
|
4
|
+
describe Datapipes::Basics do
|
5
|
+
before { $stdout = StringIO.new }
|
6
|
+
after { $stdout = STDOUT }
|
7
|
+
|
8
|
+
let(:datapipe) do
|
9
|
+
Datapipes.new(
|
10
|
+
Datapipes::Basics::List.new,
|
11
|
+
Datapipes::Basics::Triple.new,
|
12
|
+
Datapipes::Basics::Print.new,
|
13
|
+
Datapipes::Pipe.new
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:out) do
|
18
|
+
(4..6).map {|i| [i, i, i] }.join("\n") + "\n"
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'runs without errors' do
|
22
|
+
datapipe.run_resource
|
23
|
+
expect($stdout.string).to eq out
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Datapipes::Composable do
|
4
|
+
context 'with valid object' do
|
5
|
+
let(:class_a) do
|
6
|
+
Class.new do
|
7
|
+
include Datapipes::Composable
|
8
|
+
|
9
|
+
def call
|
10
|
+
one
|
11
|
+
end
|
12
|
+
|
13
|
+
def one
|
14
|
+
1
|
15
|
+
end
|
16
|
+
|
17
|
+
def exec
|
18
|
+
accumulated.map(&:call)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:class_b) do
|
24
|
+
Class.new do
|
25
|
+
include Datapipes::Composable
|
26
|
+
|
27
|
+
def call
|
28
|
+
five
|
29
|
+
end
|
30
|
+
|
31
|
+
def five
|
32
|
+
5
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
let(:a) { class_a.new }
|
38
|
+
let(:b) { class_b.new }
|
39
|
+
subject { a + b }
|
40
|
+
|
41
|
+
it 'remember defined body' do
|
42
|
+
expect(subject.exec).to eq [1, 5]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: datapipes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Taiki ONO
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: A library for processing steamings.
|
84
|
+
email:
|
85
|
+
- taiks.4559@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- datapipes.gemspec
|
96
|
+
- lib/datapipes.rb
|
97
|
+
- lib/datapipes/basics.rb
|
98
|
+
- lib/datapipes/basics/list.rb
|
99
|
+
- lib/datapipes/basics/print.rb
|
100
|
+
- lib/datapipes/basics/triple.rb
|
101
|
+
- lib/datapipes/composable.rb
|
102
|
+
- lib/datapipes/pipe.rb
|
103
|
+
- lib/datapipes/sink.rb
|
104
|
+
- lib/datapipes/source.rb
|
105
|
+
- lib/datapipes/tube.rb
|
106
|
+
- lib/datapipes/version.rb
|
107
|
+
- spec/basics_spec.rb
|
108
|
+
- spec/composable_spec.rb
|
109
|
+
- spec/spec_helper.rb
|
110
|
+
homepage: ''
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.2.2
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: A library for processing steamings.
|
134
|
+
test_files:
|
135
|
+
- spec/basics_spec.rb
|
136
|
+
- spec/composable_spec.rb
|
137
|
+
- spec/spec_helper.rb
|
138
|
+
has_rdoc:
|