u-case 3.0.0.rc7 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.sh +8 -4
- data/Gemfile +9 -1
- data/README.md +191 -122
- data/README.pt-BR.md +212 -143
- data/lib/micro/case.rb +23 -17
- data/lib/micro/case/config.rb +16 -4
- data/lib/micro/case/error.rb +7 -2
- data/lib/micro/case/result.rb +58 -47
- data/lib/micro/case/result/transitions.rb +18 -0
- data/lib/micro/case/safe.rb +2 -2
- data/lib/micro/case/strict.rb +2 -2
- data/lib/micro/case/utils.rb +1 -0
- data/lib/micro/case/version.rb +1 -1
- data/lib/micro/case/with_activemodel_validation.rb +3 -1
- data/lib/micro/cases/flow.rb +18 -14
- data/lib/micro/cases/safe/flow.rb +1 -1
- data/u-case.gemspec +3 -3
- metadata +11 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5a9b11b39c8c90670c4308c91e4e887871eb8f98a1fb739c4be71885a14d0b8
|
4
|
+
data.tar.gz: d4ce16229a9afd7dd4d1a1cf8e5b11067a11a6317c6857264ba46b324b220994
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '078f264aa7ca294bcbc12e97b4ef210a11a46151adc94d7954846e81f6e6f1647896969ee8fcf40b1bf715145b7adf029f7d22d26f226c7071d29ea477ca56b7'
|
7
|
+
data.tar.gz: e5a24e5095cb1178e92919d3f953bfbc6d690242dffafb9b8cdc4ce7c00e943c9921d4013e76b3e062d4269d32b4e4f7bb133951cc0e395416090b36cbf91b36
|
data/.travis.sh
CHANGED
@@ -3,17 +3,21 @@
|
|
3
3
|
ruby_v=$(ruby -v)
|
4
4
|
|
5
5
|
ACTIVEMODEL_VERSION='3.2' bundle update
|
6
|
-
ACTIVEMODEL_VERSION='3.2' bundle exec rake test
|
6
|
+
ACTIVEMODEL_VERSION='3.2' ENABLE_TRANSITIONS='false' bundle exec rake test
|
7
|
+
ACTIVEMODEL_VERSION='3.2' ENABLE_TRANSITIONS='true' bundle exec rake test
|
7
8
|
|
8
9
|
if [[ ! $ruby_v =~ '2.2.0' ]]; then
|
9
10
|
ACTIVEMODEL_VERSION='5.2' bundle update
|
10
|
-
ACTIVEMODEL_VERSION='5.2' bundle exec rake test
|
11
|
+
ACTIVEMODEL_VERSION='5.2' ENABLE_TRANSITIONS='false' bundle exec rake test
|
12
|
+
ACTIVEMODEL_VERSION='5.2' ENABLE_TRANSITIONS='true' bundle exec rake test
|
11
13
|
fi
|
12
14
|
|
13
15
|
if [[ $ruby_v =~ '2.5.' ]] || [[ $ruby_v =~ '2.6.' ]] || [[ $ruby_v =~ '2.7.' ]]; then
|
14
16
|
ACTIVEMODEL_VERSION='6.0' bundle update
|
15
|
-
ACTIVEMODEL_VERSION='6.0' bundle exec rake test
|
17
|
+
ACTIVEMODEL_VERSION='6.0' ENABLE_TRANSITIONS='false' bundle exec rake test
|
18
|
+
ACTIVEMODEL_VERSION='6.0' ENABLE_TRANSITIONS='true' bundle exec rake test
|
16
19
|
fi
|
17
20
|
|
18
21
|
bundle update
|
19
|
-
bundle exec rake test
|
22
|
+
ENABLE_TRANSITIONS='false' bundle exec rake test
|
23
|
+
ENABLE_TRANSITIONS='true' bundle exec rake test
|
data/Gemfile
CHANGED
@@ -15,9 +15,17 @@ if activemodel_version < '6.1.0'
|
|
15
15
|
gem 'activesupport', activemodel, require: false
|
16
16
|
end
|
17
17
|
|
18
|
+
simplecov_version =
|
19
|
+
case RUBY_VERSION
|
20
|
+
when /\A2.[23]/ then '~> 0.17.1'
|
21
|
+
when /\A2.4/ then '~> 0.18.5'
|
22
|
+
else '~> 0.19'
|
23
|
+
end
|
24
|
+
|
18
25
|
group :test do
|
19
26
|
gem 'minitest', activemodel_version < '4.1' ? '~> 4.2' : '~> 5.0'
|
20
|
-
|
27
|
+
|
28
|
+
gem 'simplecov', simplecov_version, require: false
|
21
29
|
end
|
22
30
|
|
23
31
|
pry_byebug_version =
|
data/README.md
CHANGED
@@ -1,12 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
[](https://travis-ci.com/serradura/u-case)
|
4
|
-
[](https://codeclimate.com/github/serradura/u-case/maintainability)
|
5
|
-
[](https://codeclimate.com/github/serradura/u-case/test_coverage)
|
1
|
+
<p align="center">
|
2
|
+
<img src="./assets/ucase_logo_v1.png" alt="u-case - Represent use cases in a simple and powerful way while writing modular, expressive and sequentially logical code.">
|
6
3
|
|
7
|
-
<
|
4
|
+
<p align="center"><i>Represent use cases in a simple and powerful way while writing modular, expressive and sequentially logical code.</i></p>
|
5
|
+
<br>
|
6
|
+
</p>
|
8
7
|
|
9
|
-
|
8
|
+
<p align="center">
|
9
|
+
<img src="https://img.shields.io/badge/ruby-2.2+-ruby.svg?colorA=99004d&colorB=cc0066" alt="Ruby">
|
10
|
+
|
11
|
+
<a href="https://rubygems.org/gems/u-case">
|
12
|
+
<img alt="Gem" src="https://img.shields.io/gem/v/u-case.svg?style=flat-square">
|
13
|
+
</a>
|
14
|
+
|
15
|
+
<a href="https://travis-ci.com/serradura/u-case">
|
16
|
+
<img alt="Build Status" src="https://travis-ci.com/serradura/u-case.svg?branch=main">
|
17
|
+
</a>
|
18
|
+
|
19
|
+
<a href="https://codeclimate.com/github/serradura/u-case/maintainability">
|
20
|
+
<img alt="Maintainability" src="https://api.codeclimate.com/v1/badges/5c3c8ad1b0b943f88efd/maintainability">
|
21
|
+
</a>
|
22
|
+
|
23
|
+
<a href="https://codeclimate.com/github/serradura/u-case/test_coverage">
|
24
|
+
<img alt="Test Coverage" src="https://api.codeclimate.com/v1/badges/5c3c8ad1b0b943f88efd/test_coverage">
|
25
|
+
</a>
|
26
|
+
</p>
|
10
27
|
|
11
28
|
The main project goals are:
|
12
29
|
1. Easy to use and easy to learn (input **>>** process **>>** output).
|
@@ -21,7 +38,8 @@ The main project goals are:
|
|
21
38
|
|
22
39
|
Version | Documentation
|
23
40
|
--------- | -------------
|
24
|
-
|
41
|
+
4.0.0 | https://github.com/serradura/u-case/blob/main/README.md
|
42
|
+
3.1.0 | https://github.com/serradura/u-case/blob/v3.x/README.md
|
25
43
|
2.6.0 | https://github.com/serradura/u-case/blob/v2.x/README.md
|
26
44
|
1.1.0 | https://github.com/serradura/u-case/blob/v1.x/README.md
|
27
45
|
|
@@ -60,15 +78,18 @@ Version | Documentation
|
|
60
78
|
- [`Kind::Validator`](#kindvalidator)
|
61
79
|
- [`Micro::Case.config`](#microcaseconfig)
|
62
80
|
- [Benchmarks](#benchmarks)
|
63
|
-
- [`Micro::Case`
|
81
|
+
- [`Micro::Case`](#microcase)
|
64
82
|
- [Success results](#success-results)
|
65
83
|
- [Failure results](#failure-results)
|
66
|
-
- [`Micro::Cases::Flow`
|
84
|
+
- [`Micro::Cases::Flow`](#microcasesflow)
|
85
|
+
- [Running the benchmarks](#running-the-benchmarks)
|
86
|
+
- [Performance (Benchmarks IPS)](#performance-benchmarks-ips)
|
87
|
+
- [Memory profiling](#memory-profiling)
|
67
88
|
- [Comparisons](#comparisons)
|
68
89
|
- [Examples](#examples)
|
69
|
-
- [1️⃣
|
70
|
-
- [2️⃣
|
71
|
-
- [3️⃣
|
90
|
+
- [1️⃣ Users creation](#1️⃣-users-creation)
|
91
|
+
- [2️⃣ Rails App (API)](#2️⃣-rails-app-api)
|
92
|
+
- [3️⃣ CLI calculator](#3️⃣-cli-calculator)
|
72
93
|
- [4️⃣ Rescuing exceptions inside of the use cases](#4️⃣-rescuing-exceptions-inside-of-the-use-cases)
|
73
94
|
- [Development](#development)
|
74
95
|
- [Contributing](#contributing)
|
@@ -77,11 +98,12 @@ Version | Documentation
|
|
77
98
|
|
78
99
|
## Compatibility
|
79
100
|
|
80
|
-
| u-case | branch | ruby | activemodel |
|
81
|
-
| -------------- | ------- | -------- | ------------- |
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
101
|
+
| u-case | branch | ruby | activemodel | u-attributes |
|
102
|
+
| -------------- | ------- | -------- | ------------- | ------------ |
|
103
|
+
| 4.0.0 | main | >= 2.2.0 | >= 3.2, < 6.1 | ~> 2.0 |
|
104
|
+
| 3.1.0 | v3.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 1.1 |
|
105
|
+
| 2.6.0 | v2.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 1.1 |
|
106
|
+
| 1.1.0 | v1.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 1.1 |
|
85
107
|
|
86
108
|
> Note: The activemodel is an optional dependency, this module [can be enabled](#u-casewith_activemodel_validation---how-to-validate-use-case-attributes) to validate the use cases' attributes.
|
87
109
|
|
@@ -102,7 +124,7 @@ Version | Documentation
|
|
102
124
|
Add this line to your application's Gemfile:
|
103
125
|
|
104
126
|
```ruby
|
105
|
-
gem 'u-case', '~> 3.
|
127
|
+
gem 'u-case', '~> 3.1.0'
|
106
128
|
```
|
107
129
|
|
108
130
|
And then execute:
|
@@ -111,7 +133,7 @@ And then execute:
|
|
111
133
|
|
112
134
|
Or install it yourself as:
|
113
135
|
|
114
|
-
$ gem install u-case
|
136
|
+
$ gem install u-case
|
115
137
|
|
116
138
|
## Usage
|
117
139
|
|
@@ -1060,7 +1082,7 @@ class Multiply < Micro::Case
|
|
1060
1082
|
validates :a, :b, presence: true, numericality: true
|
1061
1083
|
|
1062
1084
|
def call!
|
1063
|
-
return Failure :
|
1085
|
+
return Failure :invalid_attributes, result: { errors: self.errors } if invalid?
|
1064
1086
|
|
1065
1087
|
Success result: { number: a * b }
|
1066
1088
|
end
|
@@ -1170,109 +1192,110 @@ end
|
|
1170
1192
|
|
1171
1193
|
## Benchmarks
|
1172
1194
|
|
1173
|
-
### `Micro::Case`
|
1195
|
+
### `Micro::Case`
|
1174
1196
|
|
1175
1197
|
#### Success results
|
1176
1198
|
|
1177
1199
|
| Gem / Abstraction | Iterations per second | Comparison |
|
1178
1200
|
| ----------------- | --------------------: | ----------------: |
|
1179
|
-
| Dry::Monads |
|
1180
|
-
| **Micro::Case** |
|
1181
|
-
| Interactor |
|
1182
|
-
| Trailblazer::Operation |
|
1183
|
-
| Dry::Transaction |
|
1201
|
+
| Dry::Monads | 281515.4 | _**The Fastest**_ |
|
1202
|
+
| **Micro::Case** | 151711.3 | 1.86x slower |
|
1203
|
+
| Interactor | 53016.2 | 5.31x slower |
|
1204
|
+
| Trailblazer::Operation | 38314.2 | 7.35x slower |
|
1205
|
+
| Dry::Transaction | 10440.7 | 26.96x slower |
|
1184
1206
|
|
1185
1207
|
<details>
|
1186
1208
|
<summary>Show the full <a href="https://github.com/evanphx/benchmark-ips">benchmark/ips</a> results.</summary>
|
1187
1209
|
|
1188
1210
|
```ruby
|
1189
1211
|
# Warming up --------------------------------------
|
1190
|
-
# Interactor
|
1191
|
-
# Trailblazer::Operation
|
1192
|
-
# Dry::Monads
|
1193
|
-
# Dry::Transaction
|
1194
|
-
# Micro::Case
|
1195
|
-
#
|
1196
|
-
#
|
1212
|
+
# Interactor 5.151k i/100ms
|
1213
|
+
# Trailblazer::Operation 3.805k i/100ms
|
1214
|
+
# Dry::Monads 28.153k i/100ms
|
1215
|
+
# Dry::Transaction 1.063k i/100ms
|
1216
|
+
# Micro::Case 15.159k i/100ms
|
1217
|
+
# Micro::Case::Safe 15.172k i/100ms
|
1218
|
+
# Micro::Case::Strict 12.557k i/100ms
|
1197
1219
|
|
1198
1220
|
# Calculating -------------------------------------
|
1199
|
-
# Interactor
|
1200
|
-
# Trailblazer::Operation
|
1201
|
-
# Dry::Monads
|
1202
|
-
# Dry::Transaction
|
1203
|
-
# Micro::Case
|
1204
|
-
#
|
1205
|
-
#
|
1221
|
+
# Interactor 53.016k (± 1.8%) i/s - 267.852k in 5.053967s
|
1222
|
+
# Trailblazer::Operation 38.314k (± 1.7%) i/s - 194.055k in 5.066374s
|
1223
|
+
# Dry::Monads 281.515k (± 2.4%) i/s - 1.408M in 5.003266s
|
1224
|
+
# Dry::Transaction 10.441k (± 2.1%) i/s - 53.150k in 5.092957s
|
1225
|
+
# Micro::Case 151.711k (± 1.7%) i/s - 773.109k in 5.097555s
|
1226
|
+
# Micro::Case::Safe 145.801k (± 6.7%) i/s - 728.256k in 5.022666s
|
1227
|
+
# Micro::Case::Strict 115.636k (± 8.4%) i/s - 577.622k in 5.042079s
|
1206
1228
|
|
1207
1229
|
# Comparison:
|
1208
|
-
# Dry::Monads:
|
1209
|
-
#
|
1210
|
-
#
|
1211
|
-
# Micro::Case::Strict:
|
1212
|
-
# Interactor:
|
1213
|
-
# Trailblazer::Operation:
|
1214
|
-
# Dry::Transaction:
|
1230
|
+
# Dry::Monads: 281515.4 i/s
|
1231
|
+
# Micro::Case: 151711.3 i/s - 1.86x (± 0.00) slower
|
1232
|
+
# Micro::Case::Safe: 145800.8 i/s - 1.93x (± 0.00) slower
|
1233
|
+
# Micro::Case::Strict: 115635.8 i/s - 2.43x (± 0.00) slower
|
1234
|
+
# Interactor: 53016.2 i/s - 5.31x (± 0.00) slower
|
1235
|
+
# Trailblazer::Operation: 38314.2 i/s - 7.35x (± 0.00) slower
|
1236
|
+
# Dry::Transaction: 10440.7 i/s - 26.96x (± 0.00) slower
|
1215
1237
|
```
|
1216
1238
|
</details>
|
1217
1239
|
|
1218
|
-
https://github.com/serradura/u-case/blob/main/benchmarks/use_case/
|
1240
|
+
https://github.com/serradura/u-case/blob/main/benchmarks/perfomance/use_case/success_results.rb
|
1219
1241
|
|
1220
1242
|
#### Failure results
|
1221
1243
|
|
1222
1244
|
| Gem / Abstraction | Iterations per second | Comparison |
|
1223
1245
|
| ----------------- | --------------------: | ----------------: |
|
1224
|
-
| **Micro::Case** |
|
1225
|
-
| Dry::Monads |
|
1226
|
-
| Trailblazer::Operation |
|
1227
|
-
| Interactor |
|
1228
|
-
| Dry::Transaction |
|
1246
|
+
| **Micro::Case** | 140794.0 | _**The Fastest**_ |
|
1247
|
+
| Dry::Monads | 133865.5 | 0x slower |
|
1248
|
+
| Trailblazer::Operation | 39829.9 | 3.53x slower |
|
1249
|
+
| Interactor | 23856.0 | 5.90x slower |
|
1250
|
+
| Dry::Transaction | 7975.0 | 17.65x slower |
|
1229
1251
|
|
1230
1252
|
<details>
|
1231
1253
|
<summary>Show the full <a href="https://github.com/evanphx/benchmark-ips">benchmark/ips</a> results.</summary>
|
1232
1254
|
|
1233
1255
|
```ruby
|
1234
1256
|
# Warming up --------------------------------------
|
1235
|
-
# Interactor
|
1236
|
-
# Trailblazer::Operation
|
1237
|
-
# Dry::Monads
|
1238
|
-
# Dry::Transaction
|
1239
|
-
# Micro::Case
|
1240
|
-
#
|
1241
|
-
#
|
1257
|
+
# Interactor 2.351k i/100ms
|
1258
|
+
# Trailblazer::Operation 3.941k i/100ms
|
1259
|
+
# Dry::Monads 13.567k i/100ms
|
1260
|
+
# Dry::Transaction 927.000 i/100ms
|
1261
|
+
# Micro::Case 14.959k i/100ms
|
1262
|
+
# Micro::Case::Safe 14.904k i/100ms
|
1263
|
+
# Micro::Case::Strict 12.007k i/100ms
|
1242
1264
|
|
1243
1265
|
# Calculating -------------------------------------
|
1244
|
-
# Interactor
|
1245
|
-
# Trailblazer::Operation
|
1246
|
-
# Dry::Monads
|
1247
|
-
# Dry::Transaction
|
1248
|
-
# Micro::Case
|
1249
|
-
#
|
1250
|
-
#
|
1266
|
+
# Interactor 23.856k (± 1.7%) i/s - 119.901k in 5.027585s
|
1267
|
+
# Trailblazer::Operation 39.830k (± 1.2%) i/s - 200.991k in 5.047032s
|
1268
|
+
# Dry::Monads 133.866k (± 2.5%) i/s - 678.350k in 5.070899s
|
1269
|
+
# Dry::Transaction 7.975k (± 8.6%) i/s - 39.861k in 5.036260s
|
1270
|
+
# Micro::Case 130.534k (±24.4%) i/s - 583.401k in 5.040907s
|
1271
|
+
# Micro::Case::Safe 140.794k (± 8.1%) i/s - 700.488k in 5.020935s
|
1272
|
+
# Micro::Case::Strict 102.641k (±21.3%) i/s - 480.280k in 5.020354s
|
1251
1273
|
|
1252
1274
|
# Comparison:
|
1253
|
-
#
|
1254
|
-
#
|
1255
|
-
#
|
1256
|
-
#
|
1257
|
-
# Trailblazer::Operation:
|
1258
|
-
# Interactor:
|
1259
|
-
# Dry::Transaction:
|
1275
|
+
# Micro::Case::Safe: 140794.0 i/s
|
1276
|
+
# Dry::Monads: 133865.5 i/s - same-ish: difference falls within error
|
1277
|
+
# Micro::Case: 130534.0 i/s - same-ish: difference falls within error
|
1278
|
+
# Micro::Case::Strict: 102640.7 i/s - 1.37x (± 0.00) slower
|
1279
|
+
# Trailblazer::Operation: 39829.9 i/s - 3.53x (± 0.00) slower
|
1280
|
+
# Interactor: 23856.0 i/s - 5.90x (± 0.00) slower
|
1281
|
+
# Dry::Transaction: 7975.0 i/s - 17.65x (± 0.00) slower
|
1260
1282
|
```
|
1261
1283
|
</details>
|
1262
1284
|
|
1263
|
-
https://github.com/serradura/u-case/blob/main/benchmarks/use_case/
|
1285
|
+
https://github.com/serradura/u-case/blob/main/benchmarks/perfomance/use_case/failure_results.rb
|
1264
1286
|
|
1265
1287
|
---
|
1266
1288
|
|
1267
|
-
### `Micro::Cases::Flow`
|
1289
|
+
### `Micro::Cases::Flow`
|
1268
1290
|
|
1269
|
-
| Gems / Abstraction | [Success results](https://github.com/serradura/u-case/blob/main/benchmarks/flow/
|
1291
|
+
| Gems / Abstraction | [Success results](https://github.com/serradura/u-case/blob/main/benchmarks/perfomance/flow/success_results.rb) | [Failure results](https://github.com/serradura/u-case/blob/main/benchmarks/perfomance/flow/failure_results.rb) |
|
1270
1292
|
| ------------------------------------------- | ----------------: | ----------------: |
|
1271
|
-
| Micro::Case
|
1272
|
-
| Micro::Case `then` method
|
1273
|
-
| Micro::Cases.flow | 1.
|
1274
|
-
| Micro::
|
1275
|
-
|
|
1293
|
+
| Micro::Case::Result `pipe` method | 172734.4 i/s | 153745.6 i/s |
|
1294
|
+
| Micro::Case::Result `then` method | 1.24x slower | 1.21x slower |
|
1295
|
+
| Micro::Cases.flow | 1.30x slower | 1.30x slower |
|
1296
|
+
| Micro::Case class with an inner flow | 2.05x slower | 1.98x slower |
|
1297
|
+
| Micro::Case class including itself as a step| 2.14x slower | 2.09x slower |
|
1298
|
+
| Interactor::Organizer | 7.69x slower | 7.03x slower |
|
1276
1299
|
|
1277
1300
|
\* The `Dry::Monads`, `Dry::Transaction`, `Trailblazer::Operation` gems are out of this analysis because all of them doesn't have this kind of feature.
|
1278
1301
|
|
@@ -1281,25 +1304,28 @@ https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_failure_r
|
|
1281
1304
|
|
1282
1305
|
```ruby
|
1283
1306
|
# Warming up --------------------------------------
|
1284
|
-
# Interactor::Organizer
|
1285
|
-
# Micro::Cases.flow([])
|
1286
|
-
# Micro::
|
1287
|
-
# Micro::Case
|
1288
|
-
# Micro::Case
|
1307
|
+
# Interactor::Organizer 2.163k i/100ms
|
1308
|
+
# Micro::Cases.flow([]) 13.158k i/100ms
|
1309
|
+
# Micro::Case flow in a class 8.400k i/100ms
|
1310
|
+
# Micro::Case including the class 8.008k i/100ms
|
1311
|
+
# Micro::Case::Result#| 17.151k i/100ms
|
1312
|
+
# Micro::Case::Result#then 14.121k i/100ms
|
1289
1313
|
|
1290
1314
|
# Calculating -------------------------------------
|
1291
|
-
# Interactor::Organizer
|
1292
|
-
# Micro::Cases.flow([])
|
1293
|
-
# Micro::
|
1294
|
-
# Micro::Case
|
1295
|
-
# Micro::Case
|
1315
|
+
# Interactor::Organizer 22.467k (± 1.8%) i/s - 112.476k in 5.007787s
|
1316
|
+
# Micro::Cases.flow([]) 133.183k (± 1.5%) i/s - 671.058k in 5.039815s
|
1317
|
+
# Micro::Case flow in a class 84.083k (± 1.8%) i/s - 428.400k in 5.096623s
|
1318
|
+
# Micro::Case including the class 80.574k (± 1.6%) i/s - 408.408k in 5.070029s
|
1319
|
+
# Micro::Case::Result#| 172.734k (± 1.1%) i/s - 874.701k in 5.064429s
|
1320
|
+
# Micro::Case::Result#then 139.799k (± 1.7%) i/s - 706.050k in 5.052035s
|
1296
1321
|
|
1297
1322
|
# Comparison:
|
1298
|
-
# Micro::Case
|
1299
|
-
# Micro::Case
|
1300
|
-
# Micro::Cases.flow([]):
|
1301
|
-
# Micro::
|
1302
|
-
#
|
1323
|
+
# Micro::Case::Result#|: 172734.4 i/s
|
1324
|
+
# Micro::Case::Result#then: 139799.0 i/s - 1.24x (± 0.00) slower
|
1325
|
+
# Micro::Cases.flow([]): 133182.9 i/s - 1.30x (± 0.00) slower
|
1326
|
+
# Micro::Case flow in a class: 84082.6 i/s - 2.05x (± 0.00) slower
|
1327
|
+
# Micro::Case including the class: 80574.3 i/s - 2.14x (± 0.00) slower
|
1328
|
+
# Interactor::Organizer: 22467.4 i/s - 7.69x (± 0.00) slower
|
1303
1329
|
```
|
1304
1330
|
</details>
|
1305
1331
|
|
@@ -1308,29 +1334,72 @@ https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_failure_r
|
|
1308
1334
|
|
1309
1335
|
```ruby
|
1310
1336
|
# Warming up --------------------------------------
|
1311
|
-
# Interactor::Organizer
|
1312
|
-
# Micro::Cases.flow([])
|
1313
|
-
# Micro::
|
1314
|
-
# Micro::Case
|
1315
|
-
# Micro::Case
|
1337
|
+
# Interactor::Organizer 2.167k i/100ms
|
1338
|
+
# Micro::Cases.flow([]) 11.797k i/100ms
|
1339
|
+
# Micro::Case flow in a class 7.783k i/100ms
|
1340
|
+
# Micro::Case including the class 7.097k i/100ms
|
1341
|
+
# Micro::Case::Result#| 14.398k i/100ms
|
1342
|
+
# Micro::Case::Result#then 12.719k i/100ms
|
1316
1343
|
|
1317
1344
|
# Calculating -------------------------------------
|
1318
|
-
# Interactor::Organizer
|
1319
|
-
# Micro::Cases.flow([])
|
1320
|
-
# Micro::
|
1321
|
-
# Micro::Case
|
1322
|
-
# Micro::Case
|
1345
|
+
# Interactor::Organizer 21.863k (± 2.5%) i/s - 110.517k in 5.058420s
|
1346
|
+
# Micro::Cases.flow([]) 118.124k (± 1.8%) i/s - 601.647k in 5.095102s
|
1347
|
+
# Micro::Case flow in a class 77.801k (± 1.5%) i/s - 389.150k in 5.003002s
|
1348
|
+
# Micro::Case including the class 73.533k (± 2.1%) i/s - 369.044k in 5.021076s
|
1349
|
+
# Micro::Case::Result#| 153.746k (± 1.5%) i/s - 777.492k in 5.058177s
|
1350
|
+
# Micro::Case::Result#then 126.897k (± 1.7%) i/s - 635.950k in 5.013059s
|
1323
1351
|
|
1324
1352
|
# Comparison:
|
1325
|
-
# Micro::Case
|
1326
|
-
# Micro::Case
|
1327
|
-
# Micro::Cases
|
1328
|
-
# Micro::
|
1329
|
-
#
|
1353
|
+
# Micro::Case::Result#|: 153745.6 i/s
|
1354
|
+
# Micro::Case::Result#then: 126896.6 i/s - 1.21x (± 0.00) slower
|
1355
|
+
# Micro::Cases.flow([]): 118123.9 i/s - 1.30x (± 0.00) slower
|
1356
|
+
# Micro::Case flow in a class: 77800.7 i/s - 1.98x (± 0.00) slower
|
1357
|
+
# Micro::Case including the class: 73532.9 i/s - 2.09x (± 0.00) slower
|
1358
|
+
# Interactor::Organizer: 21862.9 i/s - 7.03x (± 0.00) slower
|
1330
1359
|
```
|
1331
1360
|
</details>
|
1332
1361
|
|
1333
|
-
https://github.com/serradura/u-case/
|
1362
|
+
https://github.com/serradura/u-case/blob/main/benchmarks/perfomance/flow/
|
1363
|
+
|
1364
|
+
[⬆️ Back to Top](#table-of-contents-)
|
1365
|
+
|
1366
|
+
### Running the benchmarks
|
1367
|
+
|
1368
|
+
#### Performance (Benchmarks IPS)
|
1369
|
+
|
1370
|
+
Clone this repo and access its folder, then run the commands below:
|
1371
|
+
|
1372
|
+
**Use cases**
|
1373
|
+
|
1374
|
+
```sh
|
1375
|
+
ruby benchmarks/perfomance/use_case/failure_results.rb
|
1376
|
+
ruby benchmarks/perfomance/use_case/success_results.rb
|
1377
|
+
```
|
1378
|
+
|
1379
|
+
**Flows**
|
1380
|
+
|
1381
|
+
```sh
|
1382
|
+
ruby benchmarks/perfomance/flow/failure_results.rb
|
1383
|
+
ruby benchmarks/perfomance/flow/success_results.rb
|
1384
|
+
```
|
1385
|
+
|
1386
|
+
#### Memory profiling
|
1387
|
+
|
1388
|
+
**Use cases**
|
1389
|
+
|
1390
|
+
```sh
|
1391
|
+
./benchmarks/memory/use_case/success/with_transitions/analyze.sh
|
1392
|
+
./benchmarks/memory/use_case/success/without_transitions/analyze.sh
|
1393
|
+
```
|
1394
|
+
|
1395
|
+
**Flows**
|
1396
|
+
|
1397
|
+
```sh
|
1398
|
+
./benchmarks/memory/flow/success/with_transitions/analyze.sh
|
1399
|
+
./benchmarks/memory/flow/success/without_transitions/analyze.sh
|
1400
|
+
```
|
1401
|
+
|
1402
|
+
[⬆️ Back to Top](#table-of-contents-)
|
1334
1403
|
|
1335
1404
|
### Comparisons
|
1336
1405
|
|
@@ -1343,24 +1412,24 @@ Check it out implementations of the same use case with different gems/abstractio
|
|
1343
1412
|
|
1344
1413
|
## Examples
|
1345
1414
|
|
1346
|
-
### 1️⃣
|
1415
|
+
### 1️⃣ Users creation
|
1416
|
+
|
1417
|
+
> An example of a flow that defines steps to sanitize, validate, and persist its input data. It has all possible approaches to represent use cases using the `u-case` gem.
|
1418
|
+
>
|
1419
|
+
> Link: https://github.com/serradura/u-case/blob/main/examples/users_creation
|
1420
|
+
|
1421
|
+
### 2️⃣ Rails App (API)
|
1347
1422
|
|
1348
1423
|
> This project shows different kinds of architecture (one per commit), and in the last one, how to use the `Micro::Case` gem to handle the application business logic.
|
1349
1424
|
>
|
1350
1425
|
> Link: https://github.com/serradura/from-fat-controllers-to-use-cases
|
1351
1426
|
|
1352
|
-
###
|
1427
|
+
### 3️⃣ CLI calculator
|
1353
1428
|
|
1354
1429
|
> Rake tasks to demonstrate how to handle user data, and how to use different failure types to control the program flow.
|
1355
1430
|
>
|
1356
1431
|
> Link: https://github.com/serradura/u-case/tree/main/examples/calculator
|
1357
1432
|
|
1358
|
-
### 3️⃣ Users creation
|
1359
|
-
|
1360
|
-
> An example of a use case flow that defines steps to sanitize, validate, and persist its input data.
|
1361
|
-
>
|
1362
|
-
> Link: https://github.com/serradura/u-case/blob/main/examples/users_creation.rb
|
1363
|
-
|
1364
1433
|
### 4️⃣ Rescuing exceptions inside of the use cases
|
1365
1434
|
|
1366
1435
|
> Link: https://github.com/serradura/u-case/blob/main/examples/rescuing_exceptions.rb
|