dry-pipeline 0.0.1 → 0.0.2

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
2
  SHA1:
3
- metadata.gz: 3d77dc059fe92e42293d0c7375c2a6a9fdcf91b1
4
- data.tar.gz: f70ed0b0408a7d85000b60095aa79503245d4cbc
3
+ metadata.gz: 5704f3bc0ba8a300d2de4a9b33d7b70cde54a85c
4
+ data.tar.gz: 644d434d4ecac4e1563186049ac2eea25ae611d9
5
5
  SHA512:
6
- metadata.gz: 4ca72ecd3a5f066476a9e83ecbf275424fddf2a685d9783f906203a8eb9828bd323b5a8626cb4bbb4c2e3b211a41ca78469c824752f127d2f6bf982d7d89187a
7
- data.tar.gz: bb2558a726003d06ecfd6638045ce1fbb0164ae1f4460b21a329b5535bba225d803150d251f1c73c02ee03eb74de63ae003456fa90b52fd7236c93bcf8827958
6
+ metadata.gz: 67a6549fab836957944b1feff76393a9d16fb813bb24d519ddceb5954de58bdb0da50e617915200309c145b1ad77e71e6e3e9d5f3e57a44d58f6151dddee6b7e
7
+ data.tar.gz: ef9a8b8603af0b5be42a2e80955c3377bf389d5f68e590fdc2fad31072e44ac64419e0017cc85ab0c43b724dcab35166d7d87d904413653bf241bf7f78493b25
data/.gitignore CHANGED
@@ -2,6 +2,7 @@
2
2
  /.yardoc
3
3
  /Gemfile.lock
4
4
  /_yardoc/
5
+ /vendor/
5
6
  /coverage/
6
7
  /doc/
7
8
  /pkg/
@@ -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
@@ -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
@@ -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.2.2
4
- before_install: gem install bundler -v 1.10.6
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
@@ -2,3 +2,10 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in dry-pipeline.gemspec
4
4
  gemspec
5
+
6
+ group :tools do
7
+ gem 'rubocop'
8
+ gem 'guard'
9
+ gem 'guard-rspec'
10
+ gem 'guard-rubocop'
11
+ end
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
- # Dry::Pipeline
1
+ # Dry::Pipeline <a href="https://gitter.im/dryrb/chat" target="_blank">![Join the chat at https://gitter.im/dryrb/chat](https://badges.gitter.im/Join%20Chat.svg)</a>
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dry/pipeline`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ <a href="https://rubygems.org/gems/dry-pipeline" target="_blank">![Gem Version](https://badge.fury.io/rb/dry-pipeline.svg)</a>
4
+ <a href="https://travis-ci.org/dryrb/dry-pipeline" target="_blank">![Build Status](https://travis-ci.org/dryrb/dry-pipeline.svg?branch=master)</a>
5
+ <a href="https://gemnasium.com/dryrb/dry-pipeline" target="_blank">![Dependency Status](https://gemnasium.com/dryrb/dry-pipeline.svg)</a>
6
+ <a href="https://codeclimate.com/github/dryrb/dry-pipeline" target="_blank">![Code Climate](https://codeclimate.com/github/dryrb/dry-pipeline/badges/gpa.svg)</a>
7
+ <a href="http://inch-ci.org/github/dryrb/dry-pipeline" target="_blank">![Documentation Status](http://inch-ci.org/github/dryrb/dry-pipeline.svg?branch=master&style=flat)</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
- $ bundle
19
+ ```sh
20
+ $ bundle
21
+ ```
18
22
 
19
23
  Or install it yourself as:
20
-
21
- $ gem install dry-pipeline
24
+ ```sh
25
+ $ gem install dry-pipeline
26
+ ```
22
27
 
23
28
  ## Usage
24
29
 
25
- TODO: Write usage instructions here
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/[USERNAME]/dry-pipeline.
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
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
3
 
4
- RSpec::Core::RakeTask.new(:spec)
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 :default => :spec
9
+ task default: :spec
10
+
11
+ desc 'Run all specs in spec directory'
12
+ RSpec::Core::RakeTask.new(:spec)
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "dry/pipeline"
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 "irb"
13
+ require 'irb'
14
14
  IRB.start
@@ -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 = "dry-pipeline"
7
+ spec.name = 'dry-pipeline'
8
8
  spec.version = Dry::Pipeline::VERSION.dup
9
- spec.authors = ["Piotr Solnica"]
10
- spec.email = ["piotr.solnica@gmail.com"]
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 = "exe"
16
+ spec.bindir = 'exe'
17
17
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
- spec.require_paths = ["lib"]
18
+ spec.require_paths = ['lib']
19
19
 
20
- spec.add_development_dependency "bundler", "~> 1.10"
21
- spec.add_development_dependency "rake", "~> 10.0"
22
- spec.add_development_dependency "rspec"
20
+ spec.add_development_dependency 'bundler'
21
+ spec.add_development_dependency 'rake'
22
+ spec.add_development_dependency 'rspec'
23
23
  end
@@ -1,42 +1,19 @@
1
- require "dry/pipeline/version"
1
+ require 'dry/pipeline/composite'
2
+ require 'dry/pipeline/mixin'
3
+ require 'dry/pipeline/version'
2
4
 
3
5
  module Dry
4
- module Pipeline
5
- class Composite
6
- attr_reader :left
6
+ class Pipeline
7
+ include ::Dry::Pipeline::Mixin
7
8
 
8
- attr_reader :right
9
+ attr_reader :fn
9
10
 
10
- # @api private
11
- def initialize(left, right)
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
- module Mixin
27
- attr_reader :fn
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
@@ -0,0 +1,9 @@
1
+ module Dry
2
+ class Pipeline
3
+ module Mixin
4
+ def >>(other)
5
+ ::Dry::Pipeline::Composite.new(self, other)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  module Dry
2
- module Pipeline
3
- VERSION = '0.0.1'.freeze
2
+ class Pipeline
3
+ VERSION = '0.0.2'.freeze
4
4
  end
5
5
  end
@@ -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.1
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: 2015-08-18 00:00:00.000000000 Z
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: '1.10'
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: '1.10'
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: '10.0'
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: '10.0'
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