dry-pipeline 0.0.1 → 0.0.2
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 +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +19 -0
- data/.rubocop_todo.yml +15 -0
- data/.travis.yml +28 -2
- data/Gemfile +7 -0
- data/README.md +49 -9
- data/Rakefile +10 -4
- data/bin/console +3 -3
- data/dry-pipeline.gemspec +8 -8
- data/lib/dry/pipeline.rb +10 -33
- data/lib/dry/pipeline/composite.rb +23 -0
- data/lib/dry/pipeline/mixin.rb +9 -0
- data/lib/dry/pipeline/version.rb +2 -2
- data/rakelib/rubocop.rake +18 -0
- metadata +16 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5704f3bc0ba8a300d2de4a9b33d7b70cde54a85c
|
4
|
+
data.tar.gz: 644d434d4ecac4e1563186049ac2eea25ae611d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67a6549fab836957944b1feff76393a9d16fb813bb24d519ddceb5954de58bdb0da50e617915200309c145b1ad77e71e6e3e9d5f3e57a44d58f6151dddee6b7e
|
7
|
+
data.tar.gz: ef9a8b8603af0b5be42a2e80955c3377bf389d5f68e590fdc2fad31072e44ac64419e0017cc85ab0c43b724dcab35166d7d87d904413653bf241bf7f78493b25
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Generated by `rubocop --auto-gen-config`
|
2
|
+
inherit_from: .rubocop_todo.yml
|
3
|
+
|
4
|
+
Metrics/LineLength:
|
5
|
+
Max: 110
|
6
|
+
|
7
|
+
Lint/HandleExceptions:
|
8
|
+
Exclude:
|
9
|
+
- rakelib/*.rake
|
10
|
+
|
11
|
+
Style/LambdaCall:
|
12
|
+
EnforcedStyle: braces
|
13
|
+
|
14
|
+
Style/Documentation:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Style/FileName:
|
18
|
+
Exclude:
|
19
|
+
- lib/dry-pipeline.rb
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2015-08-19 22:11:28 +0100 using RuboCop version 0.32.0.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
7
|
+
|
8
|
+
Style/Alias:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Style/FrozenStringLiteralComment:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Style/StabbyLambdaParentheses:
|
15
|
+
EnforcedStyle: require_no_parentheses
|
data/.travis.yml
CHANGED
@@ -1,4 +1,30 @@
|
|
1
1
|
language: ruby
|
2
|
+
sudo: false
|
3
|
+
cache: bundler
|
4
|
+
bundler_args: --without console
|
5
|
+
script:
|
6
|
+
- bundle exec rspec
|
7
|
+
- bundle exec rubocop
|
2
8
|
rvm:
|
3
|
-
- 2.
|
4
|
-
|
9
|
+
- 2.0
|
10
|
+
- 2.1
|
11
|
+
- 2.2
|
12
|
+
- rbx-2
|
13
|
+
- jruby
|
14
|
+
- ruby-head
|
15
|
+
- jruby-head
|
16
|
+
env:
|
17
|
+
global:
|
18
|
+
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
19
|
+
matrix:
|
20
|
+
allow_failures:
|
21
|
+
- rvm: ruby-head
|
22
|
+
- rvm: jruby-head
|
23
|
+
notifications:
|
24
|
+
email: false
|
25
|
+
webhooks:
|
26
|
+
urls:
|
27
|
+
- https://webhooks.gitter.im/e/19098b4253a72c9796db
|
28
|
+
on_success: change # options: [always|never|change] default: always
|
29
|
+
on_failure: always # options: [always|never|change] default: always
|
30
|
+
on_start: false # default: false
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
# Dry::Pipeline
|
1
|
+
# Dry::Pipeline <a href="https://gitter.im/dryrb/chat" target="_blank"></a>
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
<a href="https://rubygems.org/gems/dry-pipeline" target="_blank"></a>
|
4
|
+
<a href="https://travis-ci.org/dryrb/dry-pipeline" target="_blank"></a>
|
5
|
+
<a href="https://gemnasium.com/dryrb/dry-pipeline" target="_blank"></a>
|
6
|
+
<a href="https://codeclimate.com/github/dryrb/dry-pipeline" target="_blank"></a>
|
7
|
+
<a href="http://inch-ci.org/github/dryrb/dry-pipeline" target="_blank"></a>
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
@@ -14,15 +16,53 @@ gem 'dry-pipeline'
|
|
14
16
|
|
15
17
|
And then execute:
|
16
18
|
|
17
|
-
|
19
|
+
```sh
|
20
|
+
$ bundle
|
21
|
+
```
|
18
22
|
|
19
23
|
Or install it yourself as:
|
20
|
-
|
21
|
-
|
24
|
+
```sh
|
25
|
+
$ gem install dry-pipeline
|
26
|
+
```
|
22
27
|
|
23
28
|
## Usage
|
24
29
|
|
25
|
-
|
30
|
+
```ruby
|
31
|
+
USERS = []
|
32
|
+
User = Struct.new(:id, :first_name, :last_name, :email)
|
33
|
+
|
34
|
+
transform_user_attributes = Dry::Pipeline.new do |user_attributes|
|
35
|
+
allowed_keys = [:id, :first_name, :last_name, :email]
|
36
|
+
|
37
|
+
user_attributes.each_with_object({}) do |(key, value), hash|
|
38
|
+
next unless allowed_keys.include?(key.to_sym)
|
39
|
+
hash[key.to_sym] = value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
validate_user_attributes = Dry::Pipeline.new do |user_attributes|
|
44
|
+
required_keys = [:first_name, :last_name, :email]
|
45
|
+
|
46
|
+
if (required_keys - user_attributes.keys).empty?
|
47
|
+
user_attributes
|
48
|
+
else
|
49
|
+
raise ':first_name, :last_name and :email must be present'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
create_user = Dry::Pipeline.new do |user_attributes|
|
54
|
+
User.new(
|
55
|
+
USERS.length.next, *user_attributes.values_at(:first_name, :last_name, :email)
|
56
|
+
).tap { |user| USERS << user }
|
57
|
+
end
|
58
|
+
|
59
|
+
(transform_user_attributes >> validate_user_attributes >> create_user)[
|
60
|
+
first_name: 'Jane',
|
61
|
+
last_name: 'Doe',
|
62
|
+
email: 'jane.doe@gmail.com'
|
63
|
+
]
|
64
|
+
# => #<struct User id=1, first_name="Jane", last_name="Doe", email="jane.doe@gmail.com">
|
65
|
+
```
|
26
66
|
|
27
67
|
## Development
|
28
68
|
|
@@ -32,5 +72,5 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
72
|
|
33
73
|
## Contributing
|
34
74
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
75
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dryrb/dry-pipeline.
|
36
76
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
-
|
2
|
-
require
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require 'bundler/gem_tasks'
|
3
3
|
|
4
|
-
|
4
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
5
|
+
|
6
|
+
require 'rspec/core'
|
7
|
+
require 'rspec/core/rake_task'
|
5
8
|
|
6
|
-
task :
|
9
|
+
task default: :spec
|
10
|
+
|
11
|
+
desc 'Run all specs in spec directory'
|
12
|
+
RSpec::Core::RakeTask.new(:spec)
|
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'dry/pipeline'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "dry/pipeline"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start
|
data/dry-pipeline.gemspec
CHANGED
@@ -4,20 +4,20 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'dry/pipeline/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'dry-pipeline'
|
8
8
|
spec.version = Dry::Pipeline::VERSION.dup
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Piotr Solnica']
|
10
|
+
spec.email = ['piotr.solnica@gmail.com']
|
11
11
|
|
12
12
|
spec.summary = 'Pipeline operator for callable objects'
|
13
13
|
spec.homepage = 'https://github.com/dryrb/dry-pipeline'
|
14
14
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
-
spec.bindir =
|
16
|
+
spec.bindir = 'exe'
|
17
17
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
-
spec.require_paths = [
|
18
|
+
spec.require_paths = ['lib']
|
19
19
|
|
20
|
-
spec.add_development_dependency
|
21
|
-
spec.add_development_dependency
|
22
|
-
spec.add_development_dependency
|
20
|
+
spec.add_development_dependency 'bundler'
|
21
|
+
spec.add_development_dependency 'rake'
|
22
|
+
spec.add_development_dependency 'rspec'
|
23
23
|
end
|
data/lib/dry/pipeline.rb
CHANGED
@@ -1,42 +1,19 @@
|
|
1
|
-
require
|
1
|
+
require 'dry/pipeline/composite'
|
2
|
+
require 'dry/pipeline/mixin'
|
3
|
+
require 'dry/pipeline/version'
|
2
4
|
|
3
5
|
module Dry
|
4
|
-
|
5
|
-
|
6
|
-
attr_reader :left
|
6
|
+
class Pipeline
|
7
|
+
include ::Dry::Pipeline::Mixin
|
7
8
|
|
8
|
-
|
9
|
+
attr_reader :fn
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
@left = left
|
13
|
-
@right = right
|
14
|
-
end
|
15
|
-
|
16
|
-
def call(value)
|
17
|
-
right.(left.(value))
|
18
|
-
end
|
19
|
-
alias_method :[], :call
|
20
|
-
|
21
|
-
def >>(other)
|
22
|
-
self.class.new(self, other)
|
23
|
-
end
|
11
|
+
def initialize(fn = nil, *, &block)
|
12
|
+
@fn = block_given? ? block : fn
|
24
13
|
end
|
25
14
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
def initialize(fn, *)
|
30
|
-
@fn = fn
|
31
|
-
end
|
32
|
-
|
33
|
-
def call(input)
|
34
|
-
fn.(input)
|
35
|
-
end
|
36
|
-
|
37
|
-
def >>(other)
|
38
|
-
Composite.new(self, other)
|
39
|
-
end
|
15
|
+
def call(input)
|
16
|
+
fn.(input)
|
40
17
|
end
|
41
18
|
end
|
42
19
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Dry
|
2
|
+
class Pipeline
|
3
|
+
class Composite
|
4
|
+
attr_reader :left
|
5
|
+
attr_reader :right
|
6
|
+
|
7
|
+
# @api private
|
8
|
+
def initialize(left, right)
|
9
|
+
@left = left
|
10
|
+
@right = right
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(value)
|
14
|
+
right.(left.(value))
|
15
|
+
end
|
16
|
+
alias_method :[], :call
|
17
|
+
|
18
|
+
def >>(other)
|
19
|
+
self.class.new(self, other)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/dry/pipeline/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
begin
|
2
|
+
require 'rubocop/rake_task'
|
3
|
+
|
4
|
+
Rake::Task[:default].enhance [:rubocop]
|
5
|
+
|
6
|
+
RuboCop::RakeTask.new do |task|
|
7
|
+
task.options << '--display-cop-names'
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :rubocop do
|
11
|
+
desc 'Generate a configuration file acting as a TODO list.'
|
12
|
+
task :auto_gen_config do
|
13
|
+
exec 'bundle exec rubocop --auto-gen-config'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
rescue LoadError
|
18
|
+
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-pipeline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-11 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
|
-
version: '
|
19
|
+
version: '0'
|
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
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,6 +61,8 @@ extra_rdoc_files: []
|
|
61
61
|
files:
|
62
62
|
- ".gitignore"
|
63
63
|
- ".rspec"
|
64
|
+
- ".rubocop.yml"
|
65
|
+
- ".rubocop_todo.yml"
|
64
66
|
- ".travis.yml"
|
65
67
|
- Gemfile
|
66
68
|
- README.md
|
@@ -70,7 +72,10 @@ files:
|
|
70
72
|
- dry-pipeline.gemspec
|
71
73
|
- lib/dry-pipeline.rb
|
72
74
|
- lib/dry/pipeline.rb
|
75
|
+
- lib/dry/pipeline/composite.rb
|
76
|
+
- lib/dry/pipeline/mixin.rb
|
73
77
|
- lib/dry/pipeline/version.rb
|
78
|
+
- rakelib/rubocop.rake
|
74
79
|
homepage: https://github.com/dryrb/dry-pipeline
|
75
80
|
licenses: []
|
76
81
|
metadata: {}
|
@@ -90,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
95
|
version: '0'
|
91
96
|
requirements: []
|
92
97
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.4.5
|
98
|
+
rubygems_version: 2.4.5.1
|
94
99
|
signing_key:
|
95
100
|
specification_version: 4
|
96
101
|
summary: Pipeline operator for callable objects
|