piperator 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5ce14dd4a45b8ce9bc5453cb30df67c1357c8903
4
- data.tar.gz: b3df089403c086b52d8f0a48d2292d9f06495c51
2
+ SHA256:
3
+ metadata.gz: af5e198f4b96db3cee04f76d28630879c8a6d7f69a83b7aef26d895ccff7051a
4
+ data.tar.gz: 236c0753cdde6275d2e9bf350b2afa839312bbe72a636eff5a190a1a6bcd8b3b
5
5
  SHA512:
6
- metadata.gz: e93f487947ca4c0bacc904b3b04d1e90a245a3bc2efa68bb2b461f3df0427b6e34182cfc01c8cb50be9ae79906de91848ee70102687b55b31d769ed4938f40d9
7
- data.tar.gz: 0a2e61d19a4533ac76bb302f6fbc505f7a8e4cf5e97f0652ab9bd6b8f34aff1e79e22d271c12656a7e7a0b0cb460be2f6f3e681bbdf6e31d4c55c06f2296499c
6
+ metadata.gz: 17220ec804befc2717354c004a9c0b038d00618a3296ac773e77a99d14333d3dafc87d73b112dc1921eeaf6c67e4b7e8e8070ba42cd983b692d9a7c73999e44c
7
+ data.tar.gz: b74fe2c27cc940c5be501ecfb429dad7a89fde7283f30f67c64840013361a32101e7d9b5fa72b590d13750b8f75bc94683139cc38bdc8d0309516d04ffc931f5
@@ -1,5 +1,10 @@
1
1
  sudo: false
2
+ cache: bundler
2
3
  language: ruby
3
4
  rvm:
4
- - 2.4.0
5
- before_install: gem install bundler -v 1.14.6
5
+ - 2.3
6
+ - 2.4
7
+ - 2.5
8
+ - 2.6
9
+ - jruby
10
+ - truffleruby
@@ -1,3 +1,7 @@
1
+ ## 1.0.0. (13 October 2019)
2
+
3
+ - add `Piperator.build` to build pipelines with DSL
4
+
1
5
  ## 0.3.0 (13 July 2017)
2
6
 
3
7
  - remove implicit wrapping to callable from `Pipeline.pipe`
data/README.md CHANGED
@@ -6,6 +6,20 @@ The library is heavily inspired by [Elixir pipe operator](https://elixirschool.c
6
6
 
7
7
  [![Build Status](https://travis-ci.org/lautis/piperator.svg?branch=master)](https://travis-ci.org/lautis/piperator)
8
8
 
9
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
10
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
11
+ **Table of Contents**
12
+
13
+ - [Installation](#installation)
14
+ - [Usage](#usage)
15
+ - [Pipelines](#pipelines)
16
+ - [Enumerators as IO objects](#enumerators-as-io-objects)
17
+ - [Development](#development)
18
+ - [Related Projects](#related-projects)
19
+ - [Contributing](#contributing)
20
+ - [License](#license)
21
+
22
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
9
23
 
10
24
  ## Installation
11
25
 
@@ -35,7 +49,16 @@ Piperator.
35
49
  # => 18
36
50
  ```
37
51
 
38
- If desired, the input enumerable can also be given as the first elmenent of the pipeline using `Piperator.wrap`.
52
+ The same could also be achieved using DSL instead of method chaining:
53
+
54
+ ```ruby
55
+ Piperator.build do
56
+ pipe(->(values) { values.lazy.map { |i| i * 3 } })
57
+ pipe(->(values) { values.sum })
58
+ end.call([1, 2, 3])
59
+ ```
60
+
61
+ If desired, the input enumerable can also be given as the first element of the pipeline using `Piperator.wrap`.
39
62
 
40
63
  ```ruby
41
64
  Piperator.
@@ -156,6 +179,12 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
156
179
 
157
180
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
158
181
 
182
+ ## Related Projects
183
+
184
+ * [D★Stream](https://github.com/ddfreyne/d-stream) - Set of extensions for writing stream-processing code.
185
+ * [ddbuffer](https://github.com/ddfreyne/ddbuffer) - Buffer enumerables/enumerators.
186
+ * [Down::ChunkedIO](https://github.com/janko-m/down/blob/master/lib/down/chunked_io.rb) - A similar IO class as Piperator::IO.
187
+
159
188
  ## Contributing
160
189
 
161
190
  Bug reports and pull requests are welcome on GitHub at https://github.com/lautis/piperator.
@@ -1,13 +1,43 @@
1
1
  require 'piperator/version'
2
2
  require 'piperator/pipeline'
3
3
  require 'piperator/io'
4
+ require 'piperator/builder'
4
5
 
5
6
  # Top-level shortcuts
6
7
  module Piperator
8
+ # Build a new pipeline using DSL. This enables easy control of the pipeline
9
+ # stucture.
10
+ #
11
+ # Piperator.build do
12
+ # wrap [1, 2, 3]
13
+ # pipe(-> (enumerable) { enumerable.map { |i| i + 1 } })
14
+ # end
15
+ # # => Pipeline that returns [2, 3, 4] called
16
+ #
17
+ # # Alternatively, the Builder is also given as argument to the block
18
+ # Piperator.build do |p|
19
+ # p.wrap [1, 2, 3]
20
+ # p.pipe(-> (enumerable) { enumerable.map { |i| i + 1 } })
21
+ # end
22
+ # # This is similar, but allows access to instance variables.
23
+ #
24
+ # @return [Pipeline] Pipeline containing defined steps
25
+ def self.build(&block)
26
+ return Pipeline.new unless block_given?
27
+
28
+ Builder.new(block&.binding).tap do |builder|
29
+ if block.arity.positive?
30
+ yield builder
31
+ else
32
+ builder.instance_eval(&block)
33
+ end
34
+ end.to_pipeline
35
+ end
36
+
7
37
  # Build a new pipeline from a callable or an enumerable object
8
38
  #
9
39
  # @see Piperator::Pipeline.pipe
10
- # @param callable An object responding to call(enumerable)
40
+ # @param enumerable An object responding to call(enumerable)
11
41
  # @return [Pipeline] A pipeline containing only the callable
12
42
  def self.pipe(enumerable)
13
43
  Pipeline.pipe(enumerable)
@@ -0,0 +1,53 @@
1
+ module Piperator
2
+ # Builder is used to provide DSL-based Pipeline building. Using Builder,
3
+ # Pipelines can be built without pipe chaining, which might be easier if
4
+ # some steps need to be included only on specific conditions.
5
+ #
6
+ # @see Piperator.build
7
+ class Builder
8
+ # Expose a chained method in Pipeline in DSL
9
+ #
10
+ # @param method_name Name of method in Pipeline
11
+ # @see Pipeline
12
+ #
13
+ # @!macro [attach] dsl_method
14
+ # @method $1
15
+ # Call Pipeline#$1 given arguments and use the return value as builder state.
16
+ #
17
+ # @see Pipeline.$1
18
+ def self.dsl_method(method_name)
19
+ define_method(method_name) do |*arguments|
20
+ @pipeline = @pipeline.send(method_name, *arguments)
21
+ end
22
+ end
23
+
24
+ dsl_method :pipe
25
+ dsl_method :wrap
26
+
27
+ def initialize(saved_binding, pipeline = Pipeline.new)
28
+ @pipeline = pipeline
29
+ @saved_binding = saved_binding
30
+ end
31
+
32
+ # Return build pipeline
33
+ #
34
+ # @return [Pipeline]
35
+ def to_pipeline
36
+ @pipeline
37
+ end
38
+
39
+ private
40
+
41
+ def method_missing(method_name, *arguments, &block)
42
+ if @saved_binding.receiver.respond_to?(method_name, true)
43
+ @saved_binding.receiver.send(method_name, *arguments, &block)
44
+ else
45
+ super
46
+ end
47
+ end
48
+
49
+ def respond_to_missing?(method_name, include_private = false)
50
+ @saved_binding.receiver.respond_to?(method_name, include_private) || super
51
+ end
52
+ end
53
+ end
@@ -1,3 +1,4 @@
1
1
  module Piperator
2
- VERSION = '0.3.0'.freeze
2
+ # Piperator version
3
+ VERSION = '1.0.0'.freeze
3
4
  end
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ['lib']
25
25
 
26
- spec.add_development_dependency 'bundler', '~> 1.14'
26
+ spec.add_development_dependency 'bundler', '>= 1.14'
27
27
  spec.add_development_dependency 'rake', '~> 12.0'
28
28
  spec.add_development_dependency 'rspec', '~> 3.0'
29
29
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: piperator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ville Lautanala
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-13 00:00:00.000000000 Z
11
+ date: 2019-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.14'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.14'
27
27
  - !ruby/object:Gem::Dependency
@@ -71,6 +71,7 @@ files:
71
71
  - bin/console
72
72
  - bin/setup
73
73
  - lib/piperator.rb
74
+ - lib/piperator/builder.rb
74
75
  - lib/piperator/io.rb
75
76
  - lib/piperator/pipeline.rb
76
77
  - lib/piperator/version.rb
@@ -94,8 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
95
  - !ruby/object:Gem::Version
95
96
  version: '0'
96
97
  requirements: []
97
- rubyforge_project:
98
- rubygems_version: 2.6.11
98
+ rubygems_version: 3.0.3
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: Composable pipelines for streaming large collections