caze 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +16 -0
- data/lib/caze.rb +19 -9
- data/lib/caze/version.rb +1 -1
- data/spec/caze_spec.rb +29 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82ba902e32ad7dd6d95716a2c36a1183f4a34a01
|
4
|
+
data.tar.gz: 40e3bb7a9736255e618ba9203f2dfee72bb234f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 270c160bdfa4de547c07b210b67d495a341a6a86c3001511d33a16670837870946e85535ca8e4f0d59e49dde44e30a2ba0d19c81dc94d6582a813ab160adcfa7
|
7
|
+
data.tar.gz: 4f57cb0efea9b52a9592cb2fb33b20673fec1415f50ec50f9118bbf815723f66428f6f3e8b7da8a4efc587acf5b62564675cb16c36e567f692616a9c60f2ba7e
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,12 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
5
5
|
|
6
|
+
## [0.1.1] - 2015-10-30
|
7
|
+
|
8
|
+
### Added
|
9
|
+
|
10
|
+
- Add support to raise errors with the use case name.
|
11
|
+
|
6
12
|
## [0.1.0] - 2015-10-20
|
7
13
|
|
8
14
|
### Added
|
data/README.md
CHANGED
@@ -57,6 +57,22 @@ Note that the transaction handler must implement `#transaction` and
|
|
57
57
|
return the value inside the block. It will also be responsible for handle errors
|
58
58
|
and rollback if necessary.
|
59
59
|
|
60
|
+
|
61
|
+
## Using exception interceptor
|
62
|
+
|
63
|
+
You can use the raise use case exception in order to know the use case name when an
|
64
|
+
error happen.
|
65
|
+
|
66
|
+
While declaring which use case your app has, you can set the option
|
67
|
+
`raise_use_case_exception` to `true`.
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
has_use_case :say_my_name, UseCases::SayMyName, raise_use_case_exception: true
|
71
|
+
```
|
72
|
+
|
73
|
+
It should intercept yours exceptions and write the use case name on it following the
|
74
|
+
pattern: `SayMyName: This is you error message Heisenberg`
|
75
|
+
|
60
76
|
## Exporting instance methods as class methods
|
61
77
|
|
62
78
|
Inside the use case classes you can use the `.export` method, so in the `UseCases::Sum` instead of this:
|
data/lib/caze.rb
CHANGED
@@ -5,6 +5,7 @@ require 'active_support/core_ext/module/delegation'
|
|
5
5
|
|
6
6
|
module Caze
|
7
7
|
class NoTransactionMethodError < StandardError; end
|
8
|
+
class UseCaseError < StandardError; end
|
8
9
|
extend ActiveSupport::Concern
|
9
10
|
|
10
11
|
module ClassMethods
|
@@ -12,21 +13,30 @@ module Caze
|
|
12
13
|
|
13
14
|
def has_use_case(use_case_name, use_case_class, options = {})
|
14
15
|
transactional = options.fetch(:transactional) { false }
|
16
|
+
raise_use_case_exception = options.fetch(:raise_use_case_exception) { false }
|
15
17
|
|
16
18
|
define_singleton_method(use_case_name, Proc.new do |*args|
|
17
19
|
use_case = get_use_case_class(use_case_class)
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
+
begin
|
22
|
+
if transactional
|
23
|
+
handler = self.transaction_handler
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
unless handler
|
26
|
+
raise NoTransactionMethodError,
|
27
|
+
"This action should be executed inside a transaction. But no transaction handler was configured."
|
28
|
+
end
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
+
handler.transaction { use_case.send(use_case_name, *args) }
|
31
|
+
else
|
32
|
+
use_case.send(use_case_name, *args)
|
33
|
+
end
|
34
|
+
rescue => e
|
35
|
+
if raise_use_case_exception
|
36
|
+
raise UseCaseError.new(e).exception("#{use_case_class}: #{e.message}")
|
37
|
+
else
|
38
|
+
raise e
|
39
|
+
end
|
30
40
|
end
|
31
41
|
end)
|
32
42
|
end
|
data/lib/caze/version.rb
CHANGED
data/spec/caze_spec.rb
CHANGED
@@ -16,10 +16,16 @@ describe Caze do
|
|
16
16
|
export :the_answer, as: :the_transactional_answer
|
17
17
|
export :the_answer, as: :the_answer_by_another_entry_point
|
18
18
|
export :the_answer, as: :the_universal_answer
|
19
|
+
export :the_answer, as: :the_transactional_and_intercepted_answer
|
20
|
+
export :the_question
|
19
21
|
|
20
22
|
def the_answer
|
21
23
|
42
|
22
24
|
end
|
25
|
+
|
26
|
+
def the_question
|
27
|
+
raise 'You did not say yet.'
|
28
|
+
end
|
23
29
|
end
|
24
30
|
|
25
31
|
class DummyUseCaseWithParam
|
@@ -44,6 +50,9 @@ describe Caze do
|
|
44
50
|
has_use_case :the_universal_answer, :DummyUseCase
|
45
51
|
has_use_case :the_answer_for, DummyUseCaseWithParam
|
46
52
|
has_use_case :the_transactional_answer, DummyUseCase, transactional: true
|
53
|
+
has_use_case :the_question, DummyUseCase, raise_use_case_exception: true
|
54
|
+
has_use_case :the_transactional_and_intercepted_answer, DummyUseCase, transactional: true,
|
55
|
+
raise_use_case_exception: true
|
47
56
|
end
|
48
57
|
end
|
49
58
|
|
@@ -102,6 +111,26 @@ describe Caze do
|
|
102
111
|
end
|
103
112
|
end
|
104
113
|
end
|
114
|
+
|
115
|
+
context 'using exception' do
|
116
|
+
context 'when the use case raises an exception' do
|
117
|
+
it 'shows the use case name' do
|
118
|
+
expect {
|
119
|
+
app.the_question
|
120
|
+
}.to raise_error('DummyUseCase: You did not say yet.')
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context 'using exception and transaction' do
|
126
|
+
context 'when the use case raises the transaction exception' do
|
127
|
+
it 'shows the use case name' do
|
128
|
+
expect {
|
129
|
+
app.the_transactional_and_intercepted_answer
|
130
|
+
}.to raise_error(/DummyUseCase: This action should be executed inside a transaction/)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
105
134
|
end
|
106
135
|
|
107
136
|
describe '.export' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: caze
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Philip Sampaio
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-10-
|
12
|
+
date: 2015-10-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|