codequest_pipes 0.3.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8927148db159660b6ead2c27a563bad7549d0a09
4
- data.tar.gz: 19984aa1944dcfeb4f25f98a4e094d7d7a30d726
3
+ metadata.gz: f4686dbe7780d8bc9a02b7371a87939c26c5a425
4
+ data.tar.gz: 2fe01e9d642064faa039e75b14374869e3593ec9
5
5
  SHA512:
6
- metadata.gz: c21098b3a8f6a3c58fe20b811601a242a2cbec7804ddc238033d7098cd9b8dd37d4d51889329408e998f32c9f2a5dacc57d99af852ee3519c16f7171c1639e39
7
- data.tar.gz: 42650f5652b26974040cda7f82db6860c09d69f616ecc3a2bf378947df5735e3304a5843023f09983373ab17c5825329655309e3728bbfc008807b15882bd328
6
+ metadata.gz: de35061ef1e1f3dedc67c5e469ead96fbd9baf50520deaec045ba427f1585ef97ebdc131e463c8b171ddd5e13e09e0a0f695c4d4a521cbf4d266d26f665a1c56
7
+ data.tar.gz: 5781bcedc1099d9ce527ec1af5a04b02602049ff9e300aa5da6360bc8bb7ef28f5d5316733fcc1cd7f080aeff0197f1b48af82b480a261727fd253f1bc67f6c3
@@ -65,5 +65,17 @@ module Pipes
65
65
  def failure?
66
66
  !success?
67
67
  end
68
+
69
+ # Printable string representation of the context
70
+ # object_id_hex explained: http://stackoverflow.com/a/2818916/3526316
71
+ #
72
+ # @return [String]
73
+ def inspect
74
+ keys = methods - Object.methods - Pipes::Context.instance_methods
75
+ fields = keys.map { |key| "#{key}=#{public_send(key).inspect}" }
76
+ fields << "@error=#{@error.inspect}"
77
+ object_id_hex = '%x' % (object_id << 1)
78
+ "#<Pipes::Context:0x00#{object_id_hex} #{fields.join(', ')}>"
79
+ end
68
80
  end # class Context
69
81
  end # module Pipes
@@ -0,0 +1,16 @@
1
+ RSpec::Matchers.define :pipe_context do |expected_hash|
2
+ def matches_or_equals?(actual, expected)
3
+ return expected.matches?(actual) if expected.respond_to?(:matches?)
4
+ expected == actual
5
+ end
6
+
7
+ match do |ctx|
8
+ return false unless ctx.is_a?(Pipes::Context)
9
+ expected_hash.all? do |key, val|
10
+ next false unless ctx.respond_to?(key)
11
+ matches_or_equals?(ctx.public_send(key), val)
12
+ end
13
+ end
14
+
15
+ diffable
16
+ end
data/spec/context_spec.rb CHANGED
@@ -1,18 +1,30 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Pipes::Context do
4
- let(:ctx) { Pipes::Context.new }
5
-
6
4
  describe '#add' do
7
5
  it 'allows adding new fields' do
8
- ctx.add(key: 'val')
9
- expect(ctx.key).to eq('val')
6
+ subject.add(key: 'val')
7
+ expect(subject.key).to eq('val')
10
8
  end
11
9
 
12
10
  it 'does not allow rewriting existing fields' do
13
- ctx.add(key: 'val')
14
- expect { ctx.add(key: 'other_val') }
11
+ subject.add(key: 'val')
12
+ expect { subject.add(key: 'other_val') }
15
13
  .to raise_error(Pipes::Context::Override)
16
14
  end
17
- end
18
- end # describe Context
15
+ end # describe '#add'
16
+
17
+ describe '#inspect' do
18
+ it 'lists all fields' do
19
+ subject.add(bacon: 'yum', raisins: 'bleh')
20
+ expect(subject.inspect)
21
+ .to match(/bacon=\"yum\", raisins=\"bleh\", @error=nil/)
22
+ end
23
+
24
+ it 'lists nested contexts' do
25
+ subject.add(nested: Pipes::Context.new(foo: 'bar'))
26
+ expect(subject.inspect)
27
+ .to match(/nested=#<Pipes::Context:0x\w+ foo="bar", @error=nil>,/)
28
+ end
29
+ end # describe '#inspect'
30
+ end # describe Pipes::Context
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ require 'rspec/matchers/fail_matchers'
3
+ require 'codequest_pipes/rspec'
4
+
5
+ RSpec.configure do |config|
6
+ config.include RSpec::Matchers::FailMatchers
7
+ end
8
+
9
+ describe 'expect(...).to match(pipe_context(expected))' do
10
+ let(:ctx) { Pipes::Context.new(foo: 'foo', bar: {}, baz: 1) }
11
+ let(:expected) { nil }
12
+
13
+ shared_examples_for 'fails_with_message' do |message|
14
+ it 'fails' do
15
+ expected_message =
16
+ message || /expected #<Pipes::Context:.+ @error=nil> to match/
17
+ expect { expect(ctx).to match(pipe_context(expected)) }
18
+ .to fail_with(expected_message)
19
+ end
20
+ end # shared_examples_for 'fails'
21
+
22
+ context 'when any key is missing' do
23
+ let(:expected) { {foo: 'foo', bacon: {}} }
24
+ it_behaves_like 'fails_with_message'
25
+ end # context 'when any key is missing'
26
+
27
+ context 'when actual is not Pipes::Context' do
28
+ let(:ctx) { 'bacon' }
29
+
30
+ it_behaves_like 'fails_with_message', /expected "bacon" to match/
31
+ end # context 'when expected is not Pipes::Context'
32
+
33
+ context 'when any key matcher fails' do
34
+ let(:expected) { {foo: 'foo', bar: {}, baz: 'bacon'} }
35
+
36
+ it_behaves_like 'fails_with_message'
37
+ end # context 'when any key matcher fails'
38
+
39
+ context 'when any value not equal' do
40
+ let(:expected) { {foo: 'foo', bar: {}, baz: 2} }
41
+
42
+ it_behaves_like 'fails_with_message'
43
+ end
44
+
45
+ context 'when all keys match' do
46
+ let(:expected) { {foo: 'foo', bar: {}, baz: 1} }
47
+ it 'succeeds' do
48
+ expect(ctx).to match(pipe_context(expected))
49
+ end
50
+ end # context 'when all keys match'
51
+ end # describe 'pipe_context'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codequest_pipes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - codequest
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-13 00:00:00.000000000 Z
11
+ date: 2016-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -50,19 +50,13 @@ executables: []
50
50
  extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
- - ".gitignore"
54
- - ".rspec"
55
- - ".travis.yml"
56
- - Gemfile
57
- - LICENSE
58
- - README.md
59
- - Rakefile
60
- - codequest_pipes.gemspec
61
53
  - lib/codequest_pipes.rb
62
54
  - lib/codequest_pipes/closure.rb
63
55
  - lib/codequest_pipes/context.rb
64
56
  - lib/codequest_pipes/pipe.rb
57
+ - lib/codequest_pipes/rspec.rb
65
58
  - spec/context_spec.rb
59
+ - spec/matcher_spec.rb
66
60
  - spec/pipe_spec.rb
67
61
  - spec/spec_helper.rb
68
62
  homepage: https://github.com/codequest-eu/codequest_pipes
@@ -85,11 +79,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
79
  version: '0'
86
80
  requirements: []
87
81
  rubyforge_project:
88
- rubygems_version: 2.5.1
82
+ rubygems_version: 2.6.8
89
83
  signing_key:
90
84
  specification_version: 4
91
85
  summary: Unix-like way to chain business objects (interactors)
92
86
  test_files:
93
87
  - spec/context_spec.rb
88
+ - spec/matcher_spec.rb
94
89
  - spec/pipe_spec.rb
95
90
  - spec/spec_helper.rb
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --format documentation
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.2.0
4
- - 2.1.0
5
- - 2.0.0
data/Gemfile DELETED
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- group :test do
6
- gem 'rspec', '~> 3.1'
7
- end
data/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2015 code quest
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.
22
-
data/README.md DELETED
@@ -1,56 +0,0 @@
1
- # Pipes [![Build Status](https://travis-ci.org/codequest-eu/codequest_pipes.svg?branch=master)](https://travis-ci.org/codequest-eu/codequest_pipes) [![codebeat badge](https://codebeat.co/badges/73f1bb7f-516f-4fc5-b241-daea42c7badd)](https://codebeat.co/projects/codequest_pipes-master-ab1a7c5f-ad5f-425a-a0f0-e56e13a04876)
2
-
3
- Pipes provide a Unix-like way to chain business objects (interactors) in Ruby.
4
-
5
- ## Installation
6
-
7
- To start using Pipes, add the library to your `Gemfile` and run `bundle install`.
8
-
9
- ```ruby
10
- gem 'codequest_pipes'
11
- ```
12
-
13
- ## High-level usage example
14
-
15
- ```ruby
16
- FLOW = Projects::Match | # NOTE: each of the elements must inherit from
17
- Projects::Validate | # Pipes::Pipe!
18
- Projects::UpdatePayment |
19
- Projects::SaveWithReport
20
- context = Pipes::Context.new(project: p)
21
- FLOW.call(context)
22
- ```
23
-
24
- ## Pipe
25
-
26
- Pipes provide a way to describe business transactions in a stateless
27
- and reusable way. Let's create a few pipes from plain Ruby classes.
28
-
29
- ```ruby
30
- class PaymentPipe < Pipes::Pipe
31
- require_context :user # flow will fail if precondition not met
32
- provide_context :transaction # flow will fail if postcondition not met
33
-
34
- def call
35
- result = PaymentService.create_transaction(user)
36
- add(transaction: result.transaction)
37
- end
38
- end
39
- ```
40
-
41
- Note how we've only had to implement the `call` method for the magic to start happening. When calling these objects you'd be using the class method `call` instead and passing a `Pipes::Context` objects to it. All unknown messages (like `user`) in two examples above are passed to the `context` which is an instance variable of every object inheriting from `Pipes::Pipe`.
42
-
43
- ## Context
44
-
45
- Each Pipe requires an instance `Pipes::Context` to be passed on `.call` invokation. It provides append-only data container for Pipes: you can add data to a context at any time using the `add` method but the same call will raise an error if you try to modify an existing key.
46
-
47
- Made with ❤️ by [code quest](http://www.codequest.com)
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
data/Rakefile DELETED
@@ -1,9 +0,0 @@
1
- begin
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
7
- rescue LoadError
8
- # no rspec available
9
- end
@@ -1,19 +0,0 @@
1
- # encoding: utf-8
2
-
3
- Gem::Specification.new do |spec|
4
- spec.name = 'codequest_pipes'
5
- spec.version = '0.3.0'
6
-
7
- spec.author = 'codequest'
8
- spec.email = 'hello@codequest.com'
9
- spec.description = 'Pipes provides a Unix-like way to chain business objects'
10
- spec.summary = 'Unix-like way to chain business objects (interactors)'
11
- spec.homepage = 'https://github.com/codequest-eu/codequest_pipes'
12
- spec.license = 'MIT'
13
-
14
- spec.files = `git ls-files`.split($RS)
15
- spec.test_files = spec.files.grep(/^spec/)
16
-
17
- spec.add_development_dependency 'bundler', '~> 1.6', '>= 1.6.9'
18
- spec.add_development_dependency 'rake', '~> 10.3'
19
- end