sequential_workflow 0.0.3 → 0.0.5

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: 44813cdc0ed419b3cdb33f0bf07bbb5256431506
4
- data.tar.gz: d6b8161462fa64ae7e24a692485e3c4c27c1bb2b
3
+ metadata.gz: 4560cdb72eede9486d425b49e056c3af117dee2b
4
+ data.tar.gz: 6c8020fa67b523c4728592f427a01ee68c7f9144
5
5
  SHA512:
6
- metadata.gz: 2ac844182ad358d44f9aa1ab65b7b3cbc0ebef8d164f0986446d6edf13cc370ddff0b93296ea834cc2b5dd82c6448fa37bf4baf655b8e0c8488df425bb089cde
7
- data.tar.gz: ae6c0e96f738c6bd8dfb7635fd18371dae54f643e5e810ee0e441ad5505449975771c4500938250110d0464c377c3cdff288edbc6954394c934ab117e4895d51
6
+ metadata.gz: 62ab68344fa9689ab19bfe1499826b2bd2848e3b72c1b86589fad0602af4a6dc36ea407b5e8cea20e96c7f9e23389373664afb39bca119047b5f5cfda046547b
7
+ data.tar.gz: 23420f2c44edc2d3be24d2c4a7f190a78490cfb8a458d070ad9690cc6294b1e834e7dbb557e79734d7ffa91f913cd7d4c8b2376da94db958095d6da16841f3b1
@@ -1,3 +1,3 @@
1
1
  module SequentialWorkflow
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -12,20 +12,20 @@ module SequentialWorkflow
12
12
  end
13
13
 
14
14
  def catch(catch_with)
15
- method(catch_with).call(@reason)
15
+ method(catch_with).call(@reason) if rejected?
16
16
  end
17
17
 
18
- def then(on_success, rescue_with)
18
+ def then(on_success, rescue_with = nil)
19
19
  case workflow_state
20
20
  when :fulfilled
21
21
  result = method(on_success).call(@value)
22
22
  fulfill result
23
23
  when :rejected
24
- method(rescue_with).call(@reason)
24
+ method(rescue_with).call(@reason) if rescue_with
25
25
  self
26
26
  end
27
27
  rescue => e
28
- reject(e)
28
+ reject e
29
29
  end
30
30
 
31
31
  def fulfill(value)
@@ -39,4 +39,8 @@ module SequentialWorkflow
39
39
  @reason = e
40
40
  self
41
41
  end
42
+
43
+ def rejected?
44
+ @workflow_state == :rejected
45
+ end
42
46
  end
@@ -5,18 +5,26 @@ RSpec.describe 'SequentialWorkflow' do
5
5
 
6
6
  def execute_workflow
7
7
  start(:bar)
8
- .then(:first_method, nil)
9
- .then(:second_method, :handle_previous_error)
10
- .catch(:catch_method)
8
+ .then(:one)
9
+ .then(:two)
10
+ .then(:three, :handle_previous_error)
11
+ .then(:four)
12
+ .catch(:catch_method)
11
13
  end
12
14
 
13
15
  def bar
14
16
  end
15
17
 
16
- def first_method(value)
18
+ def one(value)
17
19
  end
18
20
 
19
- def second_method(value)
21
+ def two(value)
22
+ end
23
+
24
+ def three(value)
25
+ end
26
+
27
+ def four(value)
20
28
  end
21
29
 
22
30
  def handle_previous_error(e)
@@ -42,14 +50,14 @@ RSpec.describe 'SequentialWorkflow' do
42
50
  end
43
51
 
44
52
  it 'calls the next method with @value' do
45
- expect(foo).to receive(:first_method).with(value)
53
+ expect(foo).to receive(:one).with(value)
46
54
  foo.execute_workflow
47
55
  end
48
56
  end
49
57
 
50
58
  context 'on rejection' do
51
59
  before do
52
- allow(foo).to receive(:first_method).and_raise('Error')
60
+ allow(foo).to receive(:one).and_raise('Error')
53
61
  end
54
62
 
55
63
  it 'calls the rescue method' do
@@ -63,15 +71,28 @@ RSpec.describe 'SequentialWorkflow' do
63
71
  end
64
72
 
65
73
  it "doesn't call subsequent methods" do
74
+ expect(foo).not_to receive(:two)
75
+ foo.execute_workflow
76
+ end
77
+ end
78
+
79
+ end
80
+ describe '#catch' do
81
+ context 'on :rejected' do
82
+ before do
83
+ allow(foo).to receive(:one).and_raise('Error')
84
+ end
85
+
86
+ it 'runs the catch method' do
87
+ expect(foo).to receive(:catch_method).with(RuntimeError)
66
88
  foo.execute_workflow
67
- expect(foo).not_to receive(:second_method)
68
89
  end
69
90
  end
70
91
 
71
- describe '#catch' do
72
- it 'runs if :rejected' do
92
+ context 'on :fulfilled' do
93
+ it 'does not run the catch method' do
94
+ expect(foo).not_to receive(:catch_method)
73
95
  foo.execute_workflow
74
- expect(foo).not_to receive(:catch_method).with(RuntimeError)
75
96
  end
76
97
  end
77
98
  end
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequential_workflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dinshaw
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-20 00:00:00.000000000 Z
11
+ date: 2014-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
- version_requirements: !ruby/object:Gem::Requirement
15
+ requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.7'
20
- requirement: !ruby/object:Gem::Requirement
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
21
23
  requirements:
22
- - - ~>
24
+ - - "~>"
23
25
  - !ruby/object:Gem::Version
24
26
  version: '1.7'
25
- prerelease: false
26
- type: :development
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
- version_requirements: !ruby/object:Gem::Requirement
29
+ requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
- requirement: !ruby/object:Gem::Requirement
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
35
37
  requirements:
36
- - - ~>
38
+ - - "~>"
37
39
  - !ruby/object:Gem::Version
38
40
  version: '10.0'
39
- prerelease: false
40
- type: :development
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
- version_requirements: !ruby/object:Gem::Requirement
43
+ requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3.0'
48
- requirement: !ruby/object:Gem::Requirement
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
49
51
  requirements:
50
- - - ~>
52
+ - - "~>"
51
53
  - !ruby/object:Gem::Version
52
54
  version: '3.0'
53
- prerelease: false
54
- type: :development
55
55
  description: Manage sequential work-flows.
56
56
  email:
57
57
  - gobhai@gmail.com
@@ -59,7 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
62
+ - ".gitignore"
63
63
  - Gemfile
64
64
  - LICENSE.txt
65
65
  - README.md
@@ -72,24 +72,24 @@ homepage: ''
72
72
  licenses:
73
73
  - MIT
74
74
  metadata: {}
75
- post_install_message:
75
+ post_install_message:
76
76
  rdoc_options: []
77
77
  require_paths:
78
78
  - lib
79
79
  required_ruby_version: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - '>='
81
+ - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - '>='
86
+ - - ">="
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  requirements: []
90
- rubyforge_project:
91
- rubygems_version: 2.1.9
92
- signing_key:
90
+ rubyforge_project:
91
+ rubygems_version: 2.2.2
92
+ signing_key:
93
93
  specification_version: 4
94
94
  summary: Partial implementation of the Promise pattern.
95
95
  test_files: