caze 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -1
- data/lib/caze.rb +16 -2
- data/lib/caze/version.rb +1 -1
- data/spec/caze_spec.rb +22 -5
- 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: 4348280a267c35d66793ac71a0bbef6ff6ee3513
|
4
|
+
data.tar.gz: dd7ecc669f618e9067493246a2210a69b5caa65e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b63e83e36489b90fb83d508f2309f811437a9a5d4bb8b521040423c588f0de0ebb3d4df453ecfdf1f9cbfadc208a6d742bc06c3bbd5a1e514f67bf24cb528ea
|
7
|
+
data.tar.gz: 7afbd83e99b8f85b58df53fca3a1ca2f8b4a44f1e84d65c7b050c4ddacf449f8f7d1d97d756b9c103c5ffb4bc32963d8429d94d3c8d004262d6d47fa96a828d3
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,13 @@
|
|
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.2.0] - 2016-01-07
|
7
|
+
|
8
|
+
### Change
|
9
|
+
|
10
|
+
- Raise errors from inside the use case context, so we can have names easier to identify.
|
11
|
+
- Add the complete backtrace to the raised error
|
12
|
+
|
6
13
|
## [0.1.1] - 2015-10-30
|
7
14
|
|
8
15
|
### Added
|
@@ -29,6 +36,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
29
36
|
- Change main methods to define use cases and export them.
|
30
37
|
- Add more details about the API and how to use the lib at README.
|
31
38
|
|
32
|
-
[unreleased]: https://github.com/magnetis/caze/compare/v0.0
|
39
|
+
[unreleased]: https://github.com/magnetis/caze/compare/v0.2.0...HEAD
|
40
|
+
[0.2.0]: https://github.com/magnetis/caze/compare/v0.1.1...v0.2.0
|
41
|
+
[0.1.1]: https://github.com/magnetis/caze/compare/v0.1.0...v0.1.1
|
42
|
+
[0.1.0]: https://github.com/magnetis/caze/compare/v0.0.4...v0.1.0
|
33
43
|
[0.0.4]: https://github.com/magnetis/caze/compare/v0.0.3...v0.0.4
|
34
44
|
[0.0.3]: https://github.com/magnetis/caze/compare/v0.0.2...v0.0.3
|
data/lib/caze.rb
CHANGED
@@ -5,7 +5,6 @@ require 'active_support/core_ext/module/delegation'
|
|
5
5
|
|
6
6
|
module Caze
|
7
7
|
class NoTransactionMethodError < StandardError; end
|
8
|
-
class UseCaseError < StandardError; end
|
9
8
|
extend ActiveSupport::Concern
|
10
9
|
|
11
10
|
module ClassMethods
|
@@ -33,7 +32,7 @@ module Caze
|
|
33
32
|
end
|
34
33
|
rescue => e
|
35
34
|
if raise_use_case_exception
|
36
|
-
raise
|
35
|
+
raise raise_use_case_error(use_case, e)
|
37
36
|
else
|
38
37
|
raise e
|
39
38
|
end
|
@@ -59,5 +58,20 @@ module Caze
|
|
59
58
|
|
60
59
|
use_case_class
|
61
60
|
end
|
61
|
+
|
62
|
+
# This method intends to inject the error inside the context of the use case,
|
63
|
+
# so we can identify the use case from it was raised
|
64
|
+
def raise_use_case_error(use_case, error)
|
65
|
+
demodulized_error_class = error.class.name.split('::').last
|
66
|
+
|
67
|
+
base_class = Class.new(error.class)
|
68
|
+
|
69
|
+
error_class = use_case.const_set(demodulized_error_class, base_class)
|
70
|
+
|
71
|
+
error_instance = error_class.new(error.message)
|
72
|
+
error_instance.set_backtrace(error.backtrace)
|
73
|
+
|
74
|
+
raise error_instance
|
75
|
+
end
|
62
76
|
end
|
63
77
|
end
|
data/lib/caze/version.rb
CHANGED
data/spec/caze_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe Caze do
|
|
5
5
|
before do
|
6
6
|
# Removing constant definitions if they exist
|
7
7
|
# This avoids state to be permanent through tests
|
8
|
-
[:DummyUseCase, :DummyUseCaseWithParam, :Dummy].each do |const|
|
8
|
+
[:DummyUseCase, :DummyUseCaseWithParam, :Dummy, :DummyUseCaseTest].each do |const|
|
9
9
|
Object.send(:remove_const, const) if Object.constants.include?(const)
|
10
10
|
end
|
11
11
|
|
@@ -42,6 +42,22 @@ describe Caze do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
class DummyUseCaseTest
|
46
|
+
include Caze
|
47
|
+
|
48
|
+
export :the_question
|
49
|
+
|
50
|
+
def the_question
|
51
|
+
raise 'We do not know the question'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
module DummyNamespace
|
56
|
+
include Caze
|
57
|
+
|
58
|
+
has_use_case :the_question, DummyUseCaseTest, raise_use_case_exception: true
|
59
|
+
end
|
60
|
+
|
45
61
|
module Dummy
|
46
62
|
include Caze
|
47
63
|
|
@@ -58,6 +74,7 @@ describe Caze do
|
|
58
74
|
|
59
75
|
let(:use_case) { DummyUseCase }
|
60
76
|
let(:app) { Dummy }
|
77
|
+
let(:namespaced_use_case) { DummyNamespace }
|
61
78
|
|
62
79
|
describe '.has_use_case' do
|
63
80
|
it 'delegates the message to the use case' do
|
@@ -114,10 +131,10 @@ describe Caze do
|
|
114
131
|
|
115
132
|
context 'using exception' do
|
116
133
|
context 'when the use case raises an exception' do
|
117
|
-
it '
|
134
|
+
it 'raises with the namespace of the use case' do
|
118
135
|
expect {
|
119
|
-
|
120
|
-
}.to raise_error(
|
136
|
+
namespaced_use_case.the_question
|
137
|
+
}.to raise_error(DummyUseCaseTest::RuntimeError)
|
121
138
|
end
|
122
139
|
end
|
123
140
|
end
|
@@ -127,7 +144,7 @@ describe Caze do
|
|
127
144
|
it 'shows the use case name' do
|
128
145
|
expect {
|
129
146
|
app.the_transactional_and_intercepted_answer
|
130
|
-
}.to raise_error(
|
147
|
+
}.to raise_error(Caze::NoTransactionMethodError, "This action should be executed inside a transaction. But no transaction handler was configured.")
|
131
148
|
end
|
132
149
|
end
|
133
150
|
end
|
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.
|
4
|
+
version: 0.2.0
|
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:
|
12
|
+
date: 2016-01-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|