usecasing 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- N2ZiYzViMGUwOGViZTg0NDI2NzhkMjAyMDJmNTI3Mzk4Zjk4ODc2OA==
4
+ ODY5ZTA4M2JkYTNkNzhiNmNlZWYzNWUxNjkzOWNmYzA4MzBhYWU1Nw==
5
5
  data.tar.gz: !binary |-
6
- YmIxNzExYzA2MzljNDFiZTA1M2ZkNWU0MDNlY2VhYWUwOTdhZGZmNg==
6
+ MzRmODIwMzk5ZWFjMDE1MWJjZjM5NDRhNjVhY2Q5NGVhOTgxMzcwYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NjhkYTgyODc5MTU2Y2NlN2NmOTEzNjRlY2QzOTM1OGRkMTZmMzE3OTgwM2E1
10
- NDAxOGMyMDBkYmNmZmNkNTQyYTU2MGJlMDYzZjllYTZiZGE3YTU0OGExOWY2
11
- MDAxOTA4NWFhYzE2NmE1ZjkyMWE1ZmNjZDI5YjMyNjdlNDFiZmI=
9
+ OTM1ODI3ODVjYzg4NDBjMTU1ZWFhNzIxYjg1NjAxZDJkYzRmOGIyNDJiMTg2
10
+ Y2Y5YjBhYTdmN2IzZTBmZmYwZGVkMjA5NWM0ODI4YmQzNDZhNjA4ZjllZDE0
11
+ MTgxZjdmYWE0NjFjZDY0MTJkN2VkOTM0NTFiMDVhZGJhZWU0MjE=
12
12
  data.tar.gz: !binary |-
13
- OGVhZTAxNWQwNjIwYjUyZjJlMWI0Y2Y4ZjVmM2VmNTNhZmVhNWMyOGI2ZWMw
14
- MTc4NjE2ZGMzYWMzZmYxMWVjYTAwNmE3MTkwMjJlODBiOTFlYzMwOGYyZTc4
15
- MjRlYTNhMmU5MGUwOTUzN2Y1MjJjMWM4YmI0OWY5ZjkzNzA4Mzc=
13
+ ODFhNWU5YTZkYzUxZTdiMjNhODVmYTIyOWQ3YTliM2E0MzUyY2VmMTRmMGI0
14
+ MjUwNGY2YmM3MGYwNjljMGYwMDAxZDdjNjNkNjdmNTUxNDVhNzBkMmI2Y2U3
15
+ ZGYyMzI1MDQ5MGEyODhlMDc0NzVkNDNkNTE1MjMzYzc3MDE0MDk=
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  [![Build Status](https://secure.travis-ci.org/tdantas/usecasing.png)](http://travis-ci.org/tdantas/usecasing)
7
7
  [![Dependency Status](https://gemnasium.com/tdantas/usecasing.svg)](https://gemnasium.com/tdantas/usecasing)
8
-
8
+ [![Coverage Status](https://coveralls.io/repos/tdantas/usecasing/badge.png)](https://coveralls.io/r/tdantas/usecasing)
9
9
 
10
10
  Add this line to your application's Gemfile:
11
11
 
@@ -72,14 +72,15 @@ This is what we call context, the usecase context will be shared between all cha
72
72
 
73
73
  ````
74
74
  class FindInvoice < UseCase::Base
75
+
76
+ def before
77
+ @user = context.curent_user
78
+ end
75
79
 
76
80
  def perform
77
81
 
78
- # available because it was added in the controller context
79
- user = context.current_user
80
-
81
82
  # we could do that in one before_filter
82
- invoice = user.invoices.find(context.invoice_id)
83
+ invoice = @user.invoices.find(context.invoice_id)
83
84
 
84
85
  # asign to the context make available to all chain
85
86
  context.invoice = invoice
@@ -113,9 +114,12 @@ So, after validate, we already know that the invoice exists and it is ready to b
113
114
  ````
114
115
  class FinalizeInvoice < UseCase::Base
115
116
 
117
+ def before
118
+ @invoice = context.invoice
119
+ end
120
+
116
121
  def perform
117
- invoice = context.invoice
118
- invoice.finalize! #update database with finalize state
122
+ @invoice.finalize! #update database with finalize state
119
123
  context.customer = invoice.customer
120
124
  end
121
125
 
@@ -35,7 +35,7 @@ module UseCase
35
35
  ctx = Context.new(context)
36
36
  executed = []
37
37
  execution_order.each do |usecase|
38
- break unless ctx.success?
38
+ break if !ctx.success? || ctx.stopped?
39
39
  executed.push(usecase)
40
40
  yield usecase, ctx
41
41
  end
@@ -66,6 +66,10 @@ module UseCase
66
66
  def perform; end
67
67
  def rollback; end
68
68
 
69
+ def stop!
70
+ context.stop!
71
+ end
72
+
69
73
  def failure(key, value)
70
74
  @context.failure(key, value)
71
75
  end
@@ -60,6 +60,14 @@ module UseCase
60
60
  @errors.empty?
61
61
  end
62
62
 
63
+ def stop!
64
+ @stopped = true
65
+ end
66
+
67
+ def stopped?
68
+ !!@stopped
69
+ end
70
+
63
71
  def failure(key, value)
64
72
  @errors.push(key, value)
65
73
  end
@@ -1,3 +1,3 @@
1
1
  module Usecasing
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
@@ -36,5 +36,4 @@ describe UseCase::ExecutionOrder do
36
36
  expect(UseCase::ExecutionOrder.run(EOCreate)).to eql([EORepeatedSMS, EOAlert, EORepeatedSMS, EOCreate])
37
37
  end
38
38
  end
39
-
40
39
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,11 @@
1
1
  require 'usecasing'
2
2
 
3
+ if ENV["TRAVIS"]
4
+ require "coveralls"
5
+ Coveralls.wear!
6
+ end
7
+
8
+
3
9
  RSpec.configure do |config|
4
10
  config.treat_symbols_as_metadata_keys_with_true_values = true
5
11
  config.run_all_when_everything_filtered = true
@@ -278,6 +278,46 @@ describe UseCase::Base do
278
278
 
279
279
  end
280
280
 
281
+ context 'stopping the flow' do
282
+
283
+ FirstCase = Class.new(UseCase::Base) do
284
+ def perform
285
+ context.wizzard_name = "Gandalf"
286
+ end
287
+ end
288
+
289
+ StopCase = Class.new(UseCase::Base) do
290
+ def perform
291
+ context.result = "YOUUUU SHHHAAALLLL NOOOTTTT PASSSSSS!"
292
+ stop!
293
+ end
294
+ end
295
+
296
+ UnachievableCase = Class.new(UseCase::Base) do
297
+ def perform
298
+ context.result = "Still here! Muahaha!"
299
+ end
300
+ end
301
+
302
+ Base = Class.new(UseCase::Base) do
303
+ depends FirstCase, StopCase, UnachievableCase
304
+ end
305
+
306
+ let(:subject) { Base.perform }
307
+
308
+ it 'returns variables inserted by first dependency' do
309
+ expect(subject.wizzard_name).to eq("Gandalf")
310
+ end
311
+
312
+ it 'does not have variables inserted by unachievable case' do
313
+ expect(subject.result).to eq("YOUUUU SHHHAAALLLL NOOOTTTT PASSSSSS!")
314
+ end
315
+
316
+ it 'is successfull' do
317
+ expect(subject.success?).to be_true
318
+ end
319
+ end
320
+
281
321
 
282
322
  describe '#before' do
283
323
 
data/usecasing.gemspec CHANGED
@@ -19,8 +19,9 @@ Gem::Specification.new do |gem|
19
19
 
20
20
 
21
21
  #development dependecy
22
- gem.add_development_dependency "rspec"
23
- gem.add_development_dependency "rake"
24
- gem.add_development_dependency "mocha"
25
-
22
+ gem.add_development_dependency "rspec",'~> 2.14.1'
23
+ gem.add_development_dependency "rake", '~> 10.1'
24
+ gem.add_development_dependency "mocha",'~> 1.0.0'
25
+ gem.add_development_dependency "coveralls", '~> 0.7'
26
+
26
27
  end
metadata CHANGED
@@ -1,57 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usecasing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thiago Dantas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-27 00:00:00.000000000 Z
11
+ date: 2014-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 2.14.1
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: '0'
26
+ version: 2.14.1
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: '0'
33
+ version: '10.1'
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: '0'
40
+ version: '10.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mocha
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 1.0.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 1.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.7'
55
69
  description: UseCase Driven approach to your code
56
70
  email:
57
71
  - thiago.teixeira.dantas@gmail.com