caze 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/CHANGELOG.md +28 -0
- data/README.md +22 -9
- data/Rakefile +7 -0
- data/caze.gemspec +1 -0
- data/lib/caze.rb +21 -6
- data/lib/caze/version.rb +1 -1
- data/spec/caze_spec.rb +24 -2
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99a71bded9755881944f839759a8d2c9d8aa521f
|
4
|
+
data.tar.gz: 57c4a32446ab668e9c1f3939010c8695abf279f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32950a65706b076730f5dd61dcf0280fe0dc8425ca154e50e9e1213c8a726f7937adec28ebea7bd1d369eb74a0b7ae4190756dc37d39ff50991e0fc0daf47ee6
|
7
|
+
data.tar.gz: 372c8062bda691df0d8ae6fff1cc89508fcbc0ddcacdca31c15973d6c05c4faff26f2328a8a7586b0e5655e4655593d5e2781fda056432b069b07ca6d5d05d9d
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Change log
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
5
|
+
|
6
|
+
## [0.1.0] - 2015-10-20
|
7
|
+
|
8
|
+
### Added
|
9
|
+
|
10
|
+
- Add support to define use cases as string.
|
11
|
+
- Add CHANGELOG.md following the [Keep a changelog](http://keepachangelog.com/).
|
12
|
+
|
13
|
+
## [0.0.4] - 2015-04-10
|
14
|
+
|
15
|
+
### Fixed
|
16
|
+
|
17
|
+
- Fix the transactional method dispatch.
|
18
|
+
|
19
|
+
## [0.0.3] - 2015-02-05
|
20
|
+
|
21
|
+
### Changed
|
22
|
+
|
23
|
+
- Change main methods to define use cases and export them.
|
24
|
+
- Add more details about the API and how to use the lib at README.
|
25
|
+
|
26
|
+
[unreleased]: https://github.com/magnetis/caze/compare/v0.0.4...HEAD
|
27
|
+
[0.0.4]: https://github.com/magnetis/caze/compare/v0.0.3...v0.0.4
|
28
|
+
[0.0.3]: https://github.com/magnetis/caze/compare/v0.0.2...v0.0.3
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Caze
|
2
2
|
|
3
|
+
[![Build status](https://img.shields.io/travis/magnetis/caze.svg)](https://travis-ci.org/magnetis/caze)
|
4
|
+
[![Gem version](https://img.shields.io/gem/v/caze.svg)](https://rubygems.org/gems/caze)
|
5
|
+
[![Downloads](https://img.shields.io/gem/dt/caze.svg)](https://rubygems.org/gems/caze)
|
6
|
+
|
3
7
|
This is a simple DSL to declare use cases as entry points of a module.
|
4
8
|
The purpose is to avoid the verbose declarations.
|
5
9
|
|
@@ -10,11 +14,11 @@ Instead of doing this:
|
|
10
14
|
```ruby
|
11
15
|
module Project
|
12
16
|
def self.sum(x, y)
|
13
|
-
UseCases::Sum.
|
17
|
+
UseCases::Sum.sum(x, y)
|
14
18
|
end
|
15
19
|
|
16
20
|
def self.subtract(x, y)
|
17
|
-
UseCases::Subtract.
|
21
|
+
UseCases::Subtract.subtract(x, y)
|
18
22
|
end
|
19
23
|
end
|
20
24
|
```
|
@@ -27,8 +31,8 @@ require 'caze'
|
|
27
31
|
module Project
|
28
32
|
include Caze
|
29
33
|
|
30
|
-
has_use_case sum
|
31
|
-
has_use_case subtract
|
34
|
+
has_use_case :sum, UseCases::Sum
|
35
|
+
has_use_case :subtract, UseCases::Subtract
|
32
36
|
end
|
33
37
|
```
|
34
38
|
|
@@ -46,7 +50,7 @@ While declaring which use cases your app has, you can set the option
|
|
46
50
|
`transactional` to `true`.
|
47
51
|
|
48
52
|
```ruby
|
49
|
-
|
53
|
+
has_use_case :wow, UseCases::Wow, transactional: true
|
50
54
|
```
|
51
55
|
|
52
56
|
Note that the transaction handler must implement `#transaction` and
|
@@ -61,8 +65,8 @@ Inside the use case classes you can use the `.export` method, so in the `UseCase
|
|
61
65
|
module Project
|
62
66
|
module UseCases
|
63
67
|
class Sum
|
64
|
-
def self.
|
65
|
-
new(x,y).
|
68
|
+
def self.sum(x ,y)
|
69
|
+
new(x,y).sum
|
66
70
|
end
|
67
71
|
|
68
72
|
def initialize(x, y)
|
@@ -102,8 +106,7 @@ end
|
|
102
106
|
```
|
103
107
|
|
104
108
|
The `as` param, tells how the class method must be named,
|
105
|
-
if it is not passed the class method will have the of the instance method.
|
106
|
-
|
109
|
+
if it is not passed the class method will have the same name of the instance method.
|
107
110
|
|
108
111
|
With this you can call your project use cases without the need to know its internals:
|
109
112
|
|
@@ -111,6 +114,16 @@ With this you can call your project use cases without the need to know its inter
|
|
111
114
|
Project.sum(4, 2) # This will call sum inside the use case `UseCases::Sum`
|
112
115
|
```
|
113
116
|
|
117
|
+
# Installation
|
118
|
+
|
119
|
+
Add to your Gemfile:
|
120
|
+
|
121
|
+
```
|
122
|
+
gem 'caze', '~> 0.4.0'
|
123
|
+
```
|
124
|
+
|
125
|
+
Run `bundle install`.
|
126
|
+
|
114
127
|
# Apache License 2.0
|
115
128
|
|
116
129
|
Check LICENSE.txt
|
data/Rakefile
CHANGED
data/caze.gemspec
CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
|
+
spec.required_ruby_version = '>= 2.0.0'
|
20
21
|
|
21
22
|
spec.add_development_dependency "bundler", "~> 1.6"
|
22
23
|
spec.add_development_dependency "rake"
|
data/lib/caze.rb
CHANGED
@@ -11,19 +11,24 @@ module Caze
|
|
11
11
|
attr_accessor :transaction_handler
|
12
12
|
|
13
13
|
def has_use_case(use_case_name, use_case_class, options = {})
|
14
|
-
transactional
|
14
|
+
transactional = options.fetch(:transactional) { false }
|
15
|
+
|
16
|
+
define_singleton_method(use_case_name, Proc.new do |*args|
|
17
|
+
use_case = get_use_case_class(use_case_class)
|
15
18
|
|
16
|
-
define_singleton_method(use_case_name, Proc.new { |*args|
|
17
19
|
if transactional
|
18
20
|
handler = self.transaction_handler
|
19
21
|
|
20
|
-
|
22
|
+
unless handler
|
23
|
+
raise NoTransactionMethodError,
|
24
|
+
"This action should be executed inside a transaction. But no transaction handler was configured."
|
25
|
+
end
|
21
26
|
|
22
|
-
handler.transaction {
|
27
|
+
handler.transaction { use_case.send(use_case_name, *args) }
|
23
28
|
else
|
24
|
-
|
29
|
+
use_case.send(use_case_name, *args)
|
25
30
|
end
|
26
|
-
|
31
|
+
end)
|
27
32
|
end
|
28
33
|
|
29
34
|
def export(method_name, options = {})
|
@@ -34,5 +39,15 @@ module Caze
|
|
34
39
|
use_case_object.send(method_name)
|
35
40
|
})
|
36
41
|
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def get_use_case_class(use_case_class)
|
46
|
+
if use_case_class.respond_to?(:upcase)
|
47
|
+
return Object.const_get(use_case_class)
|
48
|
+
end
|
49
|
+
|
50
|
+
use_case_class
|
51
|
+
end
|
37
52
|
end
|
38
53
|
end
|
data/lib/caze/version.rb
CHANGED
data/spec/caze_spec.rb
CHANGED
@@ -14,6 +14,8 @@ describe Caze do
|
|
14
14
|
|
15
15
|
export :the_answer
|
16
16
|
export :the_answer, as: :the_transactional_answer
|
17
|
+
export :the_answer, as: :the_answer_by_another_entry_point
|
18
|
+
export :the_answer, as: :the_universal_answer
|
17
19
|
|
18
20
|
def the_answer
|
19
21
|
42
|
@@ -38,6 +40,8 @@ describe Caze do
|
|
38
40
|
include Caze
|
39
41
|
|
40
42
|
has_use_case :the_answer, DummyUseCase
|
43
|
+
has_use_case :the_answer_by_another_entry_point, 'DummyUseCase'
|
44
|
+
has_use_case :the_universal_answer, :DummyUseCase
|
41
45
|
has_use_case :the_answer_for, DummyUseCaseWithParam
|
42
46
|
has_use_case :the_transactional_answer, DummyUseCase, transactional: true
|
43
47
|
end
|
@@ -47,8 +51,9 @@ describe Caze do
|
|
47
51
|
let(:app) { Dummy }
|
48
52
|
|
49
53
|
describe '.has_use_case' do
|
50
|
-
it 'delegates the
|
51
|
-
|
54
|
+
it 'delegates the message to the use case' do
|
55
|
+
expect(use_case).to receive(:the_answer)
|
56
|
+
|
52
57
|
app.the_answer
|
53
58
|
end
|
54
59
|
|
@@ -58,6 +63,22 @@ describe Caze do
|
|
58
63
|
end
|
59
64
|
end
|
60
65
|
|
66
|
+
context 'when use case class is declared as string' do
|
67
|
+
it 'delegates the message to the use case' do
|
68
|
+
expect(use_case).to receive(:the_answer_by_another_entry_point)
|
69
|
+
|
70
|
+
app.the_answer_by_another_entry_point
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'when use case class is declared as symbol' do
|
75
|
+
it 'delegates the message to the use case' do
|
76
|
+
expect(use_case).to receive(:the_universal_answer)
|
77
|
+
|
78
|
+
app.the_universal_answer
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
61
82
|
context 'using transaction' do
|
62
83
|
context 'when there is a transaction method' do
|
63
84
|
let(:transaction_handler) { double(:transaction_handler) }
|
@@ -68,6 +89,7 @@ describe Caze do
|
|
68
89
|
|
69
90
|
it 'uses the transaction handler' do
|
70
91
|
expect(transaction_handler).to receive(:transaction).and_yield
|
92
|
+
|
71
93
|
app.the_transactional_answer
|
72
94
|
end
|
73
95
|
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.0
|
4
|
+
version: 0.1.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: 2015-
|
12
|
+
date: 2015-10-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -90,6 +90,8 @@ extensions: []
|
|
90
90
|
extra_rdoc_files: []
|
91
91
|
files:
|
92
92
|
- ".gitignore"
|
93
|
+
- ".travis.yml"
|
94
|
+
- CHANGELOG.md
|
93
95
|
- Gemfile
|
94
96
|
- LICENSE.txt
|
95
97
|
- README.md
|
@@ -111,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
113
|
requirements:
|
112
114
|
- - ">="
|
113
115
|
- !ruby/object:Gem::Version
|
114
|
-
version:
|
116
|
+
version: 2.0.0
|
115
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
118
|
requirements:
|
117
119
|
- - ">="
|
@@ -119,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
121
|
version: '0'
|
120
122
|
requirements: []
|
121
123
|
rubyforge_project:
|
122
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.4.5.1
|
123
125
|
signing_key:
|
124
126
|
specification_version: 4
|
125
127
|
summary: A DSL to define use cases
|