fibeline 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +68 -0
- data/Rakefile +2 -0
- data/fibeline.gemspec +22 -0
- data/lib/fibeline/enumerable_pump.rb +15 -0
- data/lib/fibeline/filter.rb +11 -0
- data/lib/fibeline/generic_element.rb +63 -0
- data/lib/fibeline/null_pump.rb +17 -0
- data/lib/fibeline/process.rb +27 -0
- data/lib/fibeline/transformer.rb +11 -0
- data/lib/fibeline/version.rb +3 -0
- data/lib/fibeline.rb +10 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YjY2YWEzMGFiNWVmZjU2MjY4Y2E4NTAxYWI5ZWNiZTVhNjU4N2I4MQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MGQwMzQ5MjU0YjE0NTc0NjljZmU0YTZhOGQ1MTlkYThhM2I3Y2NiNQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZTRiN2FiMGUwNzZkODM1M2JiOWQ5YjZmNmM4NjlmYmNhNmEwYTVlOWY0OTFh
|
10
|
+
NjMxNjFlMGFjODQ3ZGVmMDM5NGQ0MmEyMDVkNDdjYjI3YzY2ODQ1YTAwY2Nh
|
11
|
+
ZmMwNmY0MDAyODA2M2JlMDcwODRhY2E1NWIyMWUxYTMwNDhhNTk=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MDg5MjIwZTBkMDFjMTk2MDUxNjdkMjE4MWM3MDNlOTQ4ODk0ZWI2ODUxZTJl
|
14
|
+
Yjg0MjQ1ZjI0MjhmY2FlY2RkY2QwNDEzNTZjYjA1NjMzMDcxNTg2YWY1ZGU1
|
15
|
+
MjAyMmIzMDg2NWQzODRiYTZmM2Y2NGUyMzAzNzRlNGU5MmZiNGQ=
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
/.yardoc/
|
13
|
+
/_yardoc/
|
14
|
+
/doc/
|
15
|
+
/rdoc/
|
16
|
+
/.bundle/
|
17
|
+
/vendor/bundle
|
18
|
+
/lib/bundler/man/
|
19
|
+
.ruby-version
|
20
|
+
.ruby-gemset
|
21
|
+
.rvmrc
|
22
|
+
.idea/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Christian Haase
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Fibeline
|
2
|
+
|
3
|
+
Pipelines using Fibers. Chain together a pipe of elements like in bash.
|
4
|
+
|
5
|
+
All of this cool stuff was done by Dave Thomas.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'fibeline'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install fibeline
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Please see
|
26
|
+
|
27
|
+
* http://pragdave.me/blog/2007/12/30/pipelines-using-fibers-in-ruby-19/
|
28
|
+
* http://pragdave.me/blog/2008/01/01/pipelines-using-fibers-in-ruby-19part-ii/
|
29
|
+
|
30
|
+
### Example
|
31
|
+
{{{
|
32
|
+
require 'fibeline'
|
33
|
+
|
34
|
+
class Evens < Fibeline::GenericElement
|
35
|
+
def process
|
36
|
+
value = 0
|
37
|
+
loop do
|
38
|
+
output(value)
|
39
|
+
value += 2
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
evens = Evens.new
|
45
|
+
tripler = Fibeline::Transformer.new { |val| val * 3 }
|
46
|
+
incrementer = Fibeline::Transformer.new { |val| val + 1 }
|
47
|
+
multiple_of_five = Fibeline::Filter.new { |val| val % 5 == 0 }
|
48
|
+
|
49
|
+
5.times do
|
50
|
+
puts (evens | tripler | incrementer | multiple_of_five).resume
|
51
|
+
end
|
52
|
+
}}}
|
53
|
+
|
54
|
+
{{{
|
55
|
+
find = Fibeline::ProcessTransformer.new('find -type f')
|
56
|
+
to_pathname = Fibeline::Transformer.new { |s| Pathname(s) }
|
57
|
+
realpath = Fibeline::Transformer.new(&:realpath)
|
58
|
+
|
59
|
+
puts (find | to_pathname | realpath).to_a
|
60
|
+
}}}
|
61
|
+
|
62
|
+
## Contributing
|
63
|
+
|
64
|
+
1. Fork it ( https://github.com/krissi/fibeline/fork )
|
65
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
66
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
67
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
68
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/fibeline.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fibeline/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'fibeline'
|
8
|
+
spec.version = Fibeline::VERSION
|
9
|
+
spec.authors = ['Christian Haase']
|
10
|
+
spec.email = ["github@eggchamber.net"]
|
11
|
+
spec.summary = %q{Pipelines using Fibers}
|
12
|
+
spec.homepage = 'https://github.com/krissi/fibelines'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
21
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
22
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Fibeline
|
4
|
+
class GenericElement
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
attr_writer :source
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@transformer ||= method(:transform)
|
11
|
+
@filter ||= method(:filter)
|
12
|
+
@fiber_delegate = Fiber.new do
|
13
|
+
process
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def each
|
18
|
+
while (value = resume)
|
19
|
+
yield value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def |(other=nil, &block)
|
24
|
+
other = Transformer.new(&block) if block
|
25
|
+
other.source = self
|
26
|
+
other
|
27
|
+
end
|
28
|
+
|
29
|
+
def resume
|
30
|
+
@fiber_delegate.resume
|
31
|
+
end
|
32
|
+
|
33
|
+
def process
|
34
|
+
while (value = input)
|
35
|
+
handle_value(value)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def handle_value(value)
|
40
|
+
output(@transformer.call(value)) if @filter.call(value)
|
41
|
+
end
|
42
|
+
|
43
|
+
def source
|
44
|
+
@source ||= NullPump.new
|
45
|
+
end
|
46
|
+
|
47
|
+
def input
|
48
|
+
source.resume
|
49
|
+
end
|
50
|
+
|
51
|
+
def output(value)
|
52
|
+
Fiber.yield(value)
|
53
|
+
end
|
54
|
+
|
55
|
+
def transform(value)
|
56
|
+
value
|
57
|
+
end
|
58
|
+
|
59
|
+
def filter(value)
|
60
|
+
true
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'open3'
|
4
|
+
require 'fibeline/generic_element'
|
5
|
+
|
6
|
+
module Fibeline
|
7
|
+
class ProcessTransformer < GenericElement
|
8
|
+
def initialize(*popen_arguments)
|
9
|
+
@popen_arguments = popen_arguments
|
10
|
+
super()
|
11
|
+
end
|
12
|
+
|
13
|
+
def process
|
14
|
+
Open3.popen3(*@popen_arguments) do |stdin, stdout, _|
|
15
|
+
while (value = input)
|
16
|
+
stdin.puts value
|
17
|
+
end
|
18
|
+
stdin.close
|
19
|
+
|
20
|
+
stdout.each_line do |output_line|
|
21
|
+
output(output_line.rstrip)
|
22
|
+
end
|
23
|
+
stdout.close
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/fibeline.rb
ADDED
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fibeline
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christian Haase
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- github@eggchamber.net
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- fibeline.gemspec
|
54
|
+
- lib/fibeline.rb
|
55
|
+
- lib/fibeline/enumerable_pump.rb
|
56
|
+
- lib/fibeline/filter.rb
|
57
|
+
- lib/fibeline/generic_element.rb
|
58
|
+
- lib/fibeline/null_pump.rb
|
59
|
+
- lib/fibeline/process.rb
|
60
|
+
- lib/fibeline/transformer.rb
|
61
|
+
- lib/fibeline/version.rb
|
62
|
+
homepage: https://github.com/krissi/fibelines
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.4.3
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Pipelines using Fibers
|
86
|
+
test_files: []
|