u-case 3.0.0.rc7 → 3.0.0.rc8
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/README.md +131 -101
- data/README.pt-BR.md +131 -101
- data/lib/micro/case.rb +3 -3
- data/lib/micro/case/config.rb +1 -1
- data/lib/micro/case/result.rb +17 -12
- data/lib/micro/case/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c2265a60386ce542b8ee6006a58d4fb801dcfb396d7dfcf84d342910095fcbf8
|
|
4
|
+
data.tar.gz: 1502d1a284c616860ae99e0c03fe02a81be3e9d0adc0cc75a414825b4132f792
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ab5c45e1e1e12f157a4e5f5fa596fdb778e6bd6267d5111e438094ff37e017a0452e4a1d85a39df0e63ec28876260bad8f7c4a56ca18796a95805187efe2d002
|
|
7
|
+
data.tar.gz: 6cefcdbbb39a4400bbd4c52b7ccf77f2c142958680049a3e53f4af37d1ef696fdc3a9019cde0f8f18463dd814e79e9753ef5a270eb446dbb2bee81e7c734ffab
|
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='true' bundle exec rake test
|
|
7
|
+
ACTIVEMODEL_VERSION='3.2' ENABLE_TRANSITIONS='false' 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='true' bundle exec rake test
|
|
12
|
+
ACTIVEMODEL_VERSION='5.2' ENABLE_TRANSITIONS='false' 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='true' bundle exec rake test
|
|
18
|
+
ACTIVEMODEL_VERSION='6.0' ENABLE_TRANSITIONS='false' bundle exec rake test
|
|
16
19
|
fi
|
|
17
20
|
|
|
18
21
|
bundle update
|
|
19
|
-
bundle exec rake test
|
|
22
|
+
ENABLE_TRANSITIONS='true' bundle exec rake test
|
|
23
|
+
ENABLE_TRANSITIONS='false' bundle exec rake test
|
data/README.md
CHANGED
|
@@ -21,7 +21,7 @@ The main project goals are:
|
|
|
21
21
|
|
|
22
22
|
Version | Documentation
|
|
23
23
|
--------- | -------------
|
|
24
|
-
3.0.0.
|
|
24
|
+
3.0.0.rc8 | https://github.com/serradura/u-case/blob/main/README.md
|
|
25
25
|
2.6.0 | https://github.com/serradura/u-case/blob/v2.x/README.md
|
|
26
26
|
1.1.0 | https://github.com/serradura/u-case/blob/v1.x/README.md
|
|
27
27
|
|
|
@@ -66,9 +66,9 @@ Version | Documentation
|
|
|
66
66
|
- [`Micro::Cases::Flow` (v3.0.0)](#microcasesflow-v300)
|
|
67
67
|
- [Comparisons](#comparisons)
|
|
68
68
|
- [Examples](#examples)
|
|
69
|
-
- [1️⃣
|
|
70
|
-
- [2️⃣
|
|
71
|
-
- [3️⃣
|
|
69
|
+
- [1️⃣ Users creation](#1️⃣-users-creation)
|
|
70
|
+
- [2️⃣ Rails App (API)](#2️⃣-rails-app-api)
|
|
71
|
+
- [3️⃣ CLI calculator](#3️⃣-cli-calculator)
|
|
72
72
|
- [4️⃣ Rescuing exceptions inside of the use cases](#4️⃣-rescuing-exceptions-inside-of-the-use-cases)
|
|
73
73
|
- [Development](#development)
|
|
74
74
|
- [Contributing](#contributing)
|
|
@@ -79,7 +79,7 @@ Version | Documentation
|
|
|
79
79
|
|
|
80
80
|
| u-case | branch | ruby | activemodel |
|
|
81
81
|
| -------------- | ------- | -------- | ------------- |
|
|
82
|
-
| 3.0.0.
|
|
82
|
+
| 3.0.0.rc8 | main | >= 2.2.0 | >= 3.2, < 6.1 |
|
|
83
83
|
| 2.6.0 | v2.x | >= 2.2.0 | >= 3.2, < 6.1 |
|
|
84
84
|
| 1.1.0 | v1.x | >= 2.2.0 | >= 3.2, < 6.1 |
|
|
85
85
|
|
|
@@ -102,7 +102,7 @@ Version | Documentation
|
|
|
102
102
|
Add this line to your application's Gemfile:
|
|
103
103
|
|
|
104
104
|
```ruby
|
|
105
|
-
gem 'u-case', '~> 3.0.0.
|
|
105
|
+
gem 'u-case', '~> 3.0.0.rc8'
|
|
106
106
|
```
|
|
107
107
|
|
|
108
108
|
And then execute:
|
|
@@ -1176,42 +1176,42 @@ end
|
|
|
1176
1176
|
|
|
1177
1177
|
| Gem / Abstraction | Iterations per second | Comparison |
|
|
1178
1178
|
| ----------------- | --------------------: | ----------------: |
|
|
1179
|
-
| Dry::Monads |
|
|
1180
|
-
| **Micro::Case** |
|
|
1181
|
-
| Interactor |
|
|
1182
|
-
| Trailblazer::Operation |
|
|
1183
|
-
| Dry::Transaction |
|
|
1179
|
+
| Dry::Monads | 141730.1 | _**The Fastest**_ |
|
|
1180
|
+
| **Micro::Case** | 103541.3 | 1.37x slower |
|
|
1181
|
+
| Interactor | 29100.8 | 4.87x slower |
|
|
1182
|
+
| Trailblazer::Operation | 15031.4 | 9.43x slower |
|
|
1183
|
+
| Dry::Transaction | 5674.0 | 24.98x slower |
|
|
1184
1184
|
|
|
1185
1185
|
<details>
|
|
1186
1186
|
<summary>Show the full <a href="https://github.com/evanphx/benchmark-ips">benchmark/ips</a> results.</summary>
|
|
1187
1187
|
|
|
1188
1188
|
```ruby
|
|
1189
1189
|
# Warming up --------------------------------------
|
|
1190
|
-
# Interactor
|
|
1191
|
-
# Trailblazer::Operation 1.
|
|
1192
|
-
# Dry::Monads 14.
|
|
1193
|
-
# Dry::Transaction
|
|
1194
|
-
# Micro::Case 10.
|
|
1195
|
-
# Micro::Case::Strict 8.
|
|
1196
|
-
# Micro::Case::Safe 10.
|
|
1190
|
+
# Interactor 2.915k i/100ms
|
|
1191
|
+
# Trailblazer::Operation 1.543k i/100ms
|
|
1192
|
+
# Dry::Monads 14.288k i/100ms
|
|
1193
|
+
# Dry::Transaction 571.000 i/100ms
|
|
1194
|
+
# Micro::Case 10.418k i/100ms
|
|
1195
|
+
# Micro::Case::Strict 8.296k i/100ms
|
|
1196
|
+
# Micro::Case::Safe 10.254k i/100ms
|
|
1197
1197
|
|
|
1198
1198
|
# Calculating -------------------------------------
|
|
1199
|
-
# Interactor
|
|
1200
|
-
# Trailblazer::Operation
|
|
1201
|
-
# Dry::Monads
|
|
1202
|
-
# Dry::Transaction 5.
|
|
1203
|
-
# Micro::Case
|
|
1204
|
-
# Micro::Case::Strict
|
|
1205
|
-
# Micro::Case::Safe 101.
|
|
1199
|
+
# Interactor 29.101k (± 2.1%) i/s - 145.750k in 5.010660s
|
|
1200
|
+
# Trailblazer::Operation 15.031k (± 2.0%) i/s - 75.607k in 5.032071s
|
|
1201
|
+
# Dry::Monads 141.730k (± 3.1%) i/s - 714.400k in 5.045546s
|
|
1202
|
+
# Dry::Transaction 5.674k (± 1.9%) i/s - 28.550k in 5.033564s
|
|
1203
|
+
# Micro::Case 103.541k (± 1.6%) i/s - 520.900k in 5.032077s
|
|
1204
|
+
# Micro::Case::Strict 83.045k (± 2.4%) i/s - 423.096k in 5.098031s
|
|
1205
|
+
# Micro::Case::Safe 101.662k (± 1.5%) i/s - 512.700k in 5.044386s
|
|
1206
1206
|
|
|
1207
1207
|
# Comparison:
|
|
1208
|
-
# Dry::Monads:
|
|
1209
|
-
#
|
|
1210
|
-
#
|
|
1211
|
-
# Micro::Case::Strict:
|
|
1212
|
-
# Interactor:
|
|
1213
|
-
# Trailblazer::Operation:
|
|
1214
|
-
# Dry::Transaction:
|
|
1208
|
+
# Dry::Monads: 141730.1 i/s
|
|
1209
|
+
# Micro::Case: 103541.3 i/s - 1.37x (± 0.00) slower
|
|
1210
|
+
# Micro::Case::Safe: 101662.2 i/s - 1.39x (± 0.00) slower
|
|
1211
|
+
# Micro::Case::Strict: 83044.6 i/s - 1.71x (± 0.00) slower
|
|
1212
|
+
# Interactor: 29100.8 i/s - 4.87x (± 0.00) slower
|
|
1213
|
+
# Trailblazer::Operation: 15031.4 i/s - 9.43x (± 0.00) slower
|
|
1214
|
+
# Dry::Transaction: 5674.0 i/s - 24.98x (± 0.00) slower
|
|
1215
1215
|
```
|
|
1216
1216
|
</details>
|
|
1217
1217
|
|
|
@@ -1221,42 +1221,42 @@ https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_success_r
|
|
|
1221
1221
|
|
|
1222
1222
|
| Gem / Abstraction | Iterations per second | Comparison |
|
|
1223
1223
|
| ----------------- | --------------------: | ----------------: |
|
|
1224
|
-
| **Micro::Case** |
|
|
1225
|
-
| Dry::Monads |
|
|
1226
|
-
| Trailblazer::Operation |
|
|
1227
|
-
| Interactor |
|
|
1228
|
-
| Dry::Transaction |
|
|
1224
|
+
| **Micro::Case** | 98820.8 | _**The Fastest**_ |
|
|
1225
|
+
| Dry::Monads | 71329.7 | 1.39x slower |
|
|
1226
|
+
| Trailblazer::Operation | 15034.9 | 6.57x slower |
|
|
1227
|
+
| Interactor | 13958.7 | 7.08x slower |
|
|
1228
|
+
| Dry::Transaction | 5067.5 | 19.50x slower |
|
|
1229
1229
|
|
|
1230
1230
|
<details>
|
|
1231
1231
|
<summary>Show the full <a href="https://github.com/evanphx/benchmark-ips">benchmark/ips</a> results.</summary>
|
|
1232
1232
|
|
|
1233
1233
|
```ruby
|
|
1234
1234
|
# Warming up --------------------------------------
|
|
1235
|
-
# Interactor 1.
|
|
1236
|
-
# Trailblazer::Operation 1.
|
|
1237
|
-
# Dry::Monads 7.
|
|
1238
|
-
# Dry::Transaction
|
|
1239
|
-
# Micro::Case 9.
|
|
1240
|
-
# Micro::Case::Strict 7.
|
|
1241
|
-
# Micro::Case::Safe 9.
|
|
1235
|
+
# Interactor 1.324k i/100ms
|
|
1236
|
+
# Trailblazer::Operation 1.525k i/100ms
|
|
1237
|
+
# Dry::Monads 7.126k i/100ms
|
|
1238
|
+
# Dry::Transaction 499.000 i/100ms
|
|
1239
|
+
# Micro::Case 9.919k i/100ms
|
|
1240
|
+
# Micro::Case::Strict 7.837k i/100ms
|
|
1241
|
+
# Micro::Case::Safe 9.762k i/100ms
|
|
1242
1242
|
|
|
1243
1243
|
# Calculating -------------------------------------
|
|
1244
|
-
# Interactor 13.
|
|
1245
|
-
# Trailblazer::Operation
|
|
1246
|
-
# Dry::Monads
|
|
1247
|
-
# Dry::Transaction
|
|
1248
|
-
# Micro::Case
|
|
1249
|
-
# Micro::Case::Strict
|
|
1250
|
-
# Micro::Case::Safe
|
|
1244
|
+
# Interactor 13.959k (± 2.5%) i/s - 70.172k in 5.030240s
|
|
1245
|
+
# Trailblazer::Operation 15.035k (± 2.2%) i/s - 76.250k in 5.074108s
|
|
1246
|
+
# Dry::Monads 71.330k (± 2.4%) i/s - 363.426k in 5.097993s
|
|
1247
|
+
# Dry::Transaction 5.068k (± 1.9%) i/s - 25.449k in 5.023922s
|
|
1248
|
+
# Micro::Case 98.821k (± 2.9%) i/s - 495.950k in 5.023421s
|
|
1249
|
+
# Micro::Case::Strict 79.936k (± 3.1%) i/s - 399.687k in 5.005435s
|
|
1250
|
+
# Micro::Case::Safe 98.695k (± 1.9%) i/s - 497.862k in 5.046246s
|
|
1251
1251
|
|
|
1252
1252
|
# Comparison:
|
|
1253
|
-
# Micro::Case:
|
|
1254
|
-
# Micro::Case::Safe:
|
|
1255
|
-
# Micro::Case::Strict:
|
|
1256
|
-
# Dry::Monads:
|
|
1257
|
-
# Trailblazer::Operation:
|
|
1258
|
-
# Interactor:
|
|
1259
|
-
# Dry::Transaction:
|
|
1253
|
+
# Micro::Case: 98820.8 i/s
|
|
1254
|
+
# Micro::Case::Safe: 98695.0 i/s - same-ish: difference falls within error
|
|
1255
|
+
# Micro::Case::Strict: 79935.9 i/s - 1.24x (± 0.00) slower
|
|
1256
|
+
# Dry::Monads: 71329.7 i/s - 1.39x (± 0.00) slower
|
|
1257
|
+
# Trailblazer::Operation: 15034.9 i/s - 6.57x (± 0.00) slower
|
|
1258
|
+
# Interactor: 13958.7 i/s - 7.08x (± 0.00) slower
|
|
1259
|
+
# Dry::Transaction: 5067.5 i/s - 19.50x (± 0.00) slower
|
|
1260
1260
|
```
|
|
1261
1261
|
</details>
|
|
1262
1262
|
|
|
@@ -1269,10 +1269,11 @@ https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_failure_r
|
|
|
1269
1269
|
| Gems / Abstraction | [Success results](https://github.com/serradura/u-case/blob/main/benchmarks/flow/with_success_result.rb#L40) | [Failure results](https://github.com/serradura/u-case/blob/main/benchmarks/flow/with_failure_result.rb#L40) |
|
|
1270
1270
|
| ------------------------------------------- | ----------------: | ----------------: |
|
|
1271
1271
|
| Micro::Case internal flow (private methods) | _**The Fastest**_ | _**The Fastest**_ |
|
|
1272
|
-
| Micro::Case
|
|
1273
|
-
| Micro::
|
|
1274
|
-
| Micro::Cases.
|
|
1275
|
-
|
|
|
1272
|
+
| Micro::Case internal flow (through lambdas) | 1.03x slower | 1.04x slower |
|
|
1273
|
+
| Micro::Case `then` method | 1.49x slower | 0x slower |
|
|
1274
|
+
| Micro::Cases.flow | 1.53x slower | 1.04x slower |
|
|
1275
|
+
| Micro::Cases.safe_flow | 1.54x slower | 1.04x slower |
|
|
1276
|
+
| Interactor::Organizer | 2.05x slower | 6.27x slower |
|
|
1276
1277
|
|
|
1277
1278
|
\* 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
1279
|
|
|
@@ -1281,25 +1282,40 @@ https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_failure_r
|
|
|
1281
1282
|
|
|
1282
1283
|
```ruby
|
|
1283
1284
|
# Warming up --------------------------------------
|
|
1284
|
-
# Interactor::Organizer
|
|
1285
|
-
#
|
|
1286
|
-
# Micro::Cases
|
|
1287
|
-
#
|
|
1288
|
-
# Micro::
|
|
1285
|
+
# Interactor::Organizer
|
|
1286
|
+
# 4.837k i/100ms
|
|
1287
|
+
# Micro::Cases.flow([])
|
|
1288
|
+
# 6.755k i/100ms
|
|
1289
|
+
# Micro::Cases::safe_flow([])
|
|
1290
|
+
# 6.809k i/100ms
|
|
1291
|
+
# Micro::Case flow using `then` method
|
|
1292
|
+
# 6.968k i/100ms
|
|
1293
|
+
# Micro::Case flow using private methods
|
|
1294
|
+
# 10.362k i/100ms
|
|
1295
|
+
# Micro::Case flow using private methods through lambdas
|
|
1296
|
+
# 10.258k i/100ms
|
|
1289
1297
|
|
|
1290
1298
|
# Calculating -------------------------------------
|
|
1291
|
-
# Interactor::Organizer
|
|
1292
|
-
#
|
|
1293
|
-
# Micro::Cases
|
|
1294
|
-
#
|
|
1295
|
-
# Micro::
|
|
1299
|
+
# Interactor::Organizer
|
|
1300
|
+
# 50.731k (± 1.6%) i/s - 256.361k in 5.054694s
|
|
1301
|
+
# Micro::Cases.flow([])
|
|
1302
|
+
# 67.757k (± 1.6%) i/s - 344.505k in 5.085681s
|
|
1303
|
+
# Micro::Cases::safe_flow([])
|
|
1304
|
+
# 67.613k (± 1.6%) i/s - 340.450k in 5.036562s
|
|
1305
|
+
# Micro::Case flow using `then` method
|
|
1306
|
+
# 69.483k (± 1.5%) i/s - 348.400k in 5.015351s
|
|
1307
|
+
# Micro::Case flow using private methods
|
|
1308
|
+
# 103.788k (± 1.0%) i/s - 528.462k in 5.092240s
|
|
1309
|
+
# Micro::Case flow using private methods through lambdas
|
|
1310
|
+
# 101.081k (± 1.2%) i/s - 512.900k in 5.074904s
|
|
1296
1311
|
|
|
1297
1312
|
# Comparison:
|
|
1298
|
-
# Micro::Case flow using private methods:
|
|
1299
|
-
# Micro::Case flow using
|
|
1300
|
-
# Micro::
|
|
1301
|
-
# Micro::Cases
|
|
1302
|
-
#
|
|
1313
|
+
# Micro::Case flow using private methods: 103787.5 i/s
|
|
1314
|
+
# Micro::Case flow using private methods through lambdas: 101080.6 i/s - 1.03x (± 0.00) slower
|
|
1315
|
+
# Micro::Case flow using `then` method: 69483.3 i/s - 1.49x (± 0.00) slower
|
|
1316
|
+
# Micro::Cases.flow([]): 67757.2 i/s - 1.53x (± 0.00) slower
|
|
1317
|
+
# Micro::Cases::safe_flow([]): 67613.3 i/s - 1.54x (± 0.00) slower
|
|
1318
|
+
# Interactor::Organizer: 50730.8 i/s - 2.05x (± 0.00) slower
|
|
1303
1319
|
```
|
|
1304
1320
|
</details>
|
|
1305
1321
|
|
|
@@ -1308,25 +1324,39 @@ https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_failure_r
|
|
|
1308
1324
|
|
|
1309
1325
|
```ruby
|
|
1310
1326
|
# Warming up --------------------------------------
|
|
1311
|
-
# Interactor::Organizer
|
|
1312
|
-
#
|
|
1313
|
-
# Micro::Cases
|
|
1314
|
-
#
|
|
1315
|
-
# Micro::
|
|
1316
|
-
|
|
1327
|
+
# Interactor::Organizer
|
|
1328
|
+
# 2.299k i/100ms
|
|
1329
|
+
# Micro::Cases.flow([])
|
|
1330
|
+
# 14.187k i/100ms
|
|
1331
|
+
# Micro::Cases::safe_flow([])
|
|
1332
|
+
# 13.609k i/100ms
|
|
1333
|
+
# Micro::Case flow using `then` method
|
|
1334
|
+
# 14.578k i/100ms
|
|
1335
|
+
# Micro::Case flow using private methods
|
|
1336
|
+
# 14.101k i/100ms
|
|
1337
|
+
# Micro::Case flow using private methods through lambdas
|
|
1338
|
+
# 13.670k i/100ms
|
|
1317
1339
|
# Calculating -------------------------------------
|
|
1318
|
-
# Interactor::Organizer
|
|
1319
|
-
#
|
|
1320
|
-
# Micro::Cases
|
|
1321
|
-
#
|
|
1322
|
-
# Micro::
|
|
1340
|
+
# Interactor::Organizer
|
|
1341
|
+
# 23.306k (± 2.1%) i/s - 117.249k in 5.033171s
|
|
1342
|
+
# Micro::Cases.flow([])
|
|
1343
|
+
# 140.111k (± 1.6%) i/s - 709.350k in 5.064041s
|
|
1344
|
+
# Micro::Cases::safe_flow([])
|
|
1345
|
+
# 139.927k (± 1.7%) i/s - 707.668k in 5.058971s
|
|
1346
|
+
# Micro::Case flow using `then` method
|
|
1347
|
+
# 146.073k (± 2.0%) i/s - 743.478k in 5.091741s
|
|
1348
|
+
# Micro::Case flow using private methods
|
|
1349
|
+
# 142.092k (± 1.5%) i/s - 719.151k in 5.062298s
|
|
1350
|
+
# Micro::Case flow using private methods through lambdas
|
|
1351
|
+
# 140.791k (± 1.2%) i/s - 710.840k in 5.049584s
|
|
1323
1352
|
|
|
1324
1353
|
# Comparison:
|
|
1325
|
-
# Micro::Case flow using `then` method:
|
|
1326
|
-
# Micro::Case flow using private methods:
|
|
1327
|
-
# Micro::
|
|
1328
|
-
# Micro::Cases.flow([]):
|
|
1329
|
-
#
|
|
1354
|
+
# Micro::Case flow using `then` method: 146073.0 i/s
|
|
1355
|
+
# Micro::Case flow using private methods: 142091.7 i/s - same-ish: difference falls within error
|
|
1356
|
+
# Micro::Case flow using private methods through lambdas: 140791.1 i/s - 1.04x (± 0.00) slower
|
|
1357
|
+
# Micro::Cases.flow([]): 140110.8 i/s - 1.04x (± 0.00) slower
|
|
1358
|
+
# Micro::Cases::safe_flow([]): 139926.6 i/s - 1.04x (± 0.00) slower
|
|
1359
|
+
# Interactor::Organizer: 23305.9 i/s - 6.27x (± 0.00) slower
|
|
1330
1360
|
```
|
|
1331
1361
|
</details>
|
|
1332
1362
|
|
|
@@ -1343,24 +1373,24 @@ Check it out implementations of the same use case with different gems/abstractio
|
|
|
1343
1373
|
|
|
1344
1374
|
## Examples
|
|
1345
1375
|
|
|
1346
|
-
### 1️⃣
|
|
1376
|
+
### 1️⃣ Users creation
|
|
1377
|
+
|
|
1378
|
+
> 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.
|
|
1379
|
+
>
|
|
1380
|
+
> Link: https://github.com/serradura/u-case/blob/main/examples/users_creation
|
|
1381
|
+
|
|
1382
|
+
### 2️⃣ Rails App (API)
|
|
1347
1383
|
|
|
1348
1384
|
> 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
1385
|
>
|
|
1350
1386
|
> Link: https://github.com/serradura/from-fat-controllers-to-use-cases
|
|
1351
1387
|
|
|
1352
|
-
###
|
|
1388
|
+
### 3️⃣ CLI calculator
|
|
1353
1389
|
|
|
1354
1390
|
> Rake tasks to demonstrate how to handle user data, and how to use different failure types to control the program flow.
|
|
1355
1391
|
>
|
|
1356
1392
|
> Link: https://github.com/serradura/u-case/tree/main/examples/calculator
|
|
1357
1393
|
|
|
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
1394
|
### 4️⃣ Rescuing exceptions inside of the use cases
|
|
1365
1395
|
|
|
1366
1396
|
> Link: https://github.com/serradura/u-case/blob/main/examples/rescuing_exceptions.rb
|
data/README.pt-BR.md
CHANGED
|
@@ -21,7 +21,7 @@ Principais objetivos deste projeto:
|
|
|
21
21
|
|
|
22
22
|
Versão | Documentação
|
|
23
23
|
--------- | -------------
|
|
24
|
-
3.0.0.
|
|
24
|
+
3.0.0.rc8 | https://github.com/serradura/u-case/blob/main/README.md
|
|
25
25
|
2.6.0 | https://github.com/serradura/u-case/blob/v2.x/README.md
|
|
26
26
|
1.1.0 | https://github.com/serradura/u-case/blob/v1.x/README.md
|
|
27
27
|
|
|
@@ -65,9 +65,9 @@ Versão | Documentação
|
|
|
65
65
|
- [`Micro::Cases::Flow` (v3.0.0)](#microcasesflow-v300)
|
|
66
66
|
- [Comparações](#comparações)
|
|
67
67
|
- [Exemplos](#exemplos)
|
|
68
|
-
- [1️⃣
|
|
69
|
-
- [2️⃣
|
|
70
|
-
- [3️⃣
|
|
68
|
+
- [1️⃣ Criação de usuários](#1️⃣-criação-de-usuários)
|
|
69
|
+
- [2️⃣ Rails App (API)](#2️⃣-rails-app-api)
|
|
70
|
+
- [3️⃣ CLI calculator](#3️⃣-cli-calculator)
|
|
71
71
|
- [4️⃣ Interceptando exceções dentro dos casos de uso](#4️⃣-interceptando-exceções-dentro-dos-casos-de-uso)
|
|
72
72
|
- [Desenvolvimento](#desenvolvimento)
|
|
73
73
|
- [Contribuindo](#contribuindo)
|
|
@@ -78,7 +78,7 @@ Versão | Documentação
|
|
|
78
78
|
|
|
79
79
|
| u-case | branch | ruby | activemodel |
|
|
80
80
|
| -------------- | ------- | -------- | ------------- |
|
|
81
|
-
| 3.0.0.
|
|
81
|
+
| 3.0.0.rc8 | main | >= 2.2.0 | >= 3.2, < 6.1 |
|
|
82
82
|
| 2.6.0 | v2.x | >= 2.2.0 | >= 3.2, < 6.1 |
|
|
83
83
|
| 1.1.0 | v1.x | >= 2.2.0 | >= 3.2, < 6.1 |
|
|
84
84
|
|
|
@@ -101,7 +101,7 @@ Versão | Documentação
|
|
|
101
101
|
Adicione essa linha ao Gemfile da sua aplicação:
|
|
102
102
|
|
|
103
103
|
```ruby
|
|
104
|
-
gem 'u-case', '~> 3.0.0.
|
|
104
|
+
gem 'u-case', '~> 3.0.0.rc8'
|
|
105
105
|
```
|
|
106
106
|
|
|
107
107
|
E então execute:
|
|
@@ -1180,42 +1180,42 @@ end
|
|
|
1180
1180
|
|
|
1181
1181
|
| Gem / Abstração | Iterações por segundo | Comparação |
|
|
1182
1182
|
| ----------------- | --------------------: | ----------------: |
|
|
1183
|
-
| Dry::Monads |
|
|
1184
|
-
| **Micro::Case** |
|
|
1185
|
-
| Interactor |
|
|
1186
|
-
| Trailblazer::Operation |
|
|
1187
|
-
| Dry::Transaction |
|
|
1183
|
+
| Dry::Monads | 141730.1 | _**O mais rápido**_ |
|
|
1184
|
+
| **Micro::Case** | 103541.3 | 1.37x slower |
|
|
1185
|
+
| Interactor | 29100.8 | 4.87x slower |
|
|
1186
|
+
| Trailblazer::Operation | 15031.4 | 9.43x slower |
|
|
1187
|
+
| Dry::Transaction | 5674.0 | 24.98x slower |
|
|
1188
1188
|
|
|
1189
1189
|
<details>
|
|
1190
1190
|
<summary>Show the full <a href="https://github.com/evanphx/benchmark-ips">benchmark/ips</a> results.</summary>
|
|
1191
1191
|
|
|
1192
1192
|
```ruby
|
|
1193
1193
|
# Warming up --------------------------------------
|
|
1194
|
-
# Interactor
|
|
1195
|
-
# Trailblazer::Operation 1.
|
|
1196
|
-
# Dry::Monads 14.
|
|
1197
|
-
# Dry::Transaction
|
|
1198
|
-
# Micro::Case 10.
|
|
1199
|
-
# Micro::Case::Strict 8.
|
|
1200
|
-
# Micro::Case::Safe 10.
|
|
1194
|
+
# Interactor 2.915k i/100ms
|
|
1195
|
+
# Trailblazer::Operation 1.543k i/100ms
|
|
1196
|
+
# Dry::Monads 14.288k i/100ms
|
|
1197
|
+
# Dry::Transaction 571.000 i/100ms
|
|
1198
|
+
# Micro::Case 10.418k i/100ms
|
|
1199
|
+
# Micro::Case::Strict 8.296k i/100ms
|
|
1200
|
+
# Micro::Case::Safe 10.254k i/100ms
|
|
1201
1201
|
|
|
1202
1202
|
# Calculating -------------------------------------
|
|
1203
|
-
# Interactor
|
|
1204
|
-
# Trailblazer::Operation
|
|
1205
|
-
# Dry::Monads
|
|
1206
|
-
# Dry::Transaction 5.
|
|
1207
|
-
# Micro::Case
|
|
1208
|
-
# Micro::Case::Strict
|
|
1209
|
-
# Micro::Case::Safe 101.
|
|
1203
|
+
# Interactor 29.101k (± 2.1%) i/s - 145.750k in 5.010660s
|
|
1204
|
+
# Trailblazer::Operation 15.031k (± 2.0%) i/s - 75.607k in 5.032071s
|
|
1205
|
+
# Dry::Monads 141.730k (± 3.1%) i/s - 714.400k in 5.045546s
|
|
1206
|
+
# Dry::Transaction 5.674k (± 1.9%) i/s - 28.550k in 5.033564s
|
|
1207
|
+
# Micro::Case 103.541k (± 1.6%) i/s - 520.900k in 5.032077s
|
|
1208
|
+
# Micro::Case::Strict 83.045k (± 2.4%) i/s - 423.096k in 5.098031s
|
|
1209
|
+
# Micro::Case::Safe 101.662k (± 1.5%) i/s - 512.700k in 5.044386s
|
|
1210
1210
|
|
|
1211
1211
|
# Comparison:
|
|
1212
|
-
# Dry::Monads:
|
|
1213
|
-
#
|
|
1214
|
-
#
|
|
1215
|
-
# Micro::Case::Strict:
|
|
1216
|
-
# Interactor:
|
|
1217
|
-
# Trailblazer::Operation:
|
|
1218
|
-
# Dry::Transaction:
|
|
1212
|
+
# Dry::Monads: 141730.1 i/s
|
|
1213
|
+
# Micro::Case: 103541.3 i/s - 1.37x (± 0.00) slower
|
|
1214
|
+
# Micro::Case::Safe: 101662.2 i/s - 1.39x (± 0.00) slower
|
|
1215
|
+
# Micro::Case::Strict: 83044.6 i/s - 1.71x (± 0.00) slower
|
|
1216
|
+
# Interactor: 29100.8 i/s - 4.87x (± 0.00) slower
|
|
1217
|
+
# Trailblazer::Operation: 15031.4 i/s - 9.43x (± 0.00) slower
|
|
1218
|
+
# Dry::Transaction: 5674.0 i/s - 24.98x (± 0.00) slower
|
|
1219
1219
|
```
|
|
1220
1220
|
</details>
|
|
1221
1221
|
|
|
@@ -1225,42 +1225,42 @@ https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_success_r
|
|
|
1225
1225
|
|
|
1226
1226
|
| Gem / Abstração | Iterações por segundo | Comparação |
|
|
1227
1227
|
| ----------------- | --------------------: | ----------------: |
|
|
1228
|
-
| **Micro::Case** |
|
|
1229
|
-
| Dry::Monads |
|
|
1230
|
-
| Trailblazer::Operation |
|
|
1231
|
-
| Interactor |
|
|
1232
|
-
| Dry::Transaction |
|
|
1228
|
+
| **Micro::Case** | 98820.8 | _**O mais rápido**_ |
|
|
1229
|
+
| Dry::Monads | 71329.7 | 1.39x slower |
|
|
1230
|
+
| Trailblazer::Operation | 15034.9 | 6.57x slower |
|
|
1231
|
+
| Interactor | 13958.7 | 7.08x slower |
|
|
1232
|
+
| Dry::Transaction | 5067.5 | 19.50x slower |
|
|
1233
1233
|
|
|
1234
1234
|
<details>
|
|
1235
1235
|
<summary>Mostrar o resultado completo do <a href="https://github.com/evanphx/benchmark-ips">benchmark/ips</a>.</summary>
|
|
1236
1236
|
|
|
1237
1237
|
```ruby
|
|
1238
1238
|
# Warming up --------------------------------------
|
|
1239
|
-
# Interactor 1.
|
|
1240
|
-
# Trailblazer::Operation 1.
|
|
1241
|
-
# Dry::Monads 7.
|
|
1242
|
-
# Dry::Transaction
|
|
1243
|
-
# Micro::Case 9.
|
|
1244
|
-
# Micro::Case::Strict 7.
|
|
1245
|
-
# Micro::Case::Safe 9.
|
|
1239
|
+
# Interactor 1.324k i/100ms
|
|
1240
|
+
# Trailblazer::Operation 1.525k i/100ms
|
|
1241
|
+
# Dry::Monads 7.126k i/100ms
|
|
1242
|
+
# Dry::Transaction 499.000 i/100ms
|
|
1243
|
+
# Micro::Case 9.919k i/100ms
|
|
1244
|
+
# Micro::Case::Strict 7.837k i/100ms
|
|
1245
|
+
# Micro::Case::Safe 9.762k i/100ms
|
|
1246
1246
|
|
|
1247
1247
|
# Calculating -------------------------------------
|
|
1248
|
-
# Interactor 13.
|
|
1249
|
-
# Trailblazer::Operation
|
|
1250
|
-
# Dry::Monads
|
|
1251
|
-
# Dry::Transaction
|
|
1252
|
-
# Micro::Case
|
|
1253
|
-
# Micro::Case::Strict
|
|
1254
|
-
# Micro::Case::Safe
|
|
1248
|
+
# Interactor 13.959k (± 2.5%) i/s - 70.172k in 5.030240s
|
|
1249
|
+
# Trailblazer::Operation 15.035k (± 2.2%) i/s - 76.250k in 5.074108s
|
|
1250
|
+
# Dry::Monads 71.330k (± 2.4%) i/s - 363.426k in 5.097993s
|
|
1251
|
+
# Dry::Transaction 5.068k (± 1.9%) i/s - 25.449k in 5.023922s
|
|
1252
|
+
# Micro::Case 98.821k (± 2.9%) i/s - 495.950k in 5.023421s
|
|
1253
|
+
# Micro::Case::Strict 79.936k (± 3.1%) i/s - 399.687k in 5.005435s
|
|
1254
|
+
# Micro::Case::Safe 98.695k (± 1.9%) i/s - 497.862k in 5.046246s
|
|
1255
1255
|
|
|
1256
1256
|
# Comparison:
|
|
1257
|
-
# Micro::Case:
|
|
1258
|
-
# Micro::Case::Safe:
|
|
1259
|
-
# Micro::Case::Strict:
|
|
1260
|
-
# Dry::Monads:
|
|
1261
|
-
# Trailblazer::Operation:
|
|
1262
|
-
# Interactor:
|
|
1263
|
-
# Dry::Transaction:
|
|
1257
|
+
# Micro::Case: 98820.8 i/s
|
|
1258
|
+
# Micro::Case::Safe: 98695.0 i/s - same-ish: difference falls within error
|
|
1259
|
+
# Micro::Case::Strict: 79935.9 i/s - 1.24x (± 0.00) slower
|
|
1260
|
+
# Dry::Monads: 71329.7 i/s - 1.39x (± 0.00) slower
|
|
1261
|
+
# Trailblazer::Operation: 15034.9 i/s - 6.57x (± 0.00) slower
|
|
1262
|
+
# Interactor: 13958.7 i/s - 7.08x (± 0.00) slower
|
|
1263
|
+
# Dry::Transaction: 5067.5 i/s - 19.50x (± 0.00) slower
|
|
1264
1264
|
```
|
|
1265
1265
|
</details>
|
|
1266
1266
|
|
|
@@ -1273,10 +1273,11 @@ https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_failure_r
|
|
|
1273
1273
|
| Gem / Abstração | [Resultados de sucesso](https://github.com/serradura/u-case/blob/main/benchmarks/flow/with_success_result.rb#L40) | [Resultados de falha](https://github.com/serradura/u-case/blob/main/benchmarks/flow/with_failure_result.rb#L40) |
|
|
1274
1274
|
| ------------------------------------------- | ----------------: | ----------------: |
|
|
1275
1275
|
| Micro::Case internal flow (private methods) | _**O mais rápido**_ | _**O mais rápido**_ |
|
|
1276
|
-
| Micro::Case
|
|
1277
|
-
| Micro::
|
|
1278
|
-
| Micro::Cases.
|
|
1279
|
-
|
|
|
1276
|
+
| Micro::Case internal flow (through lambdas) | 1.03x slower | 1.04x slower |
|
|
1277
|
+
| Micro::Case `then` method | 1.49x slower | 0x slower |
|
|
1278
|
+
| Micro::Cases.flow | 1.53x slower | 1.04x slower |
|
|
1279
|
+
| Micro::Cases.safe_flow | 1.54x slower | 1.04x slower |
|
|
1280
|
+
| Interactor::Organizer | 2.05x slower | 6.27x slower |
|
|
1280
1281
|
|
|
1281
1282
|
\* As gems `Dry::Monads`, `Dry::Transaction`, `Trailblazer::Operation` estão fora desta análise por não terem esse tipo de funcionalidade.
|
|
1282
1283
|
|
|
@@ -1285,25 +1286,40 @@ https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_failure_r
|
|
|
1285
1286
|
|
|
1286
1287
|
```ruby
|
|
1287
1288
|
# Warming up --------------------------------------
|
|
1288
|
-
# Interactor::Organizer
|
|
1289
|
-
#
|
|
1290
|
-
# Micro::Cases
|
|
1291
|
-
#
|
|
1292
|
-
# Micro::
|
|
1289
|
+
# Interactor::Organizer
|
|
1290
|
+
# 4.837k i/100ms
|
|
1291
|
+
# Micro::Cases.flow([])
|
|
1292
|
+
# 6.755k i/100ms
|
|
1293
|
+
# Micro::Cases::safe_flow([])
|
|
1294
|
+
# 6.809k i/100ms
|
|
1295
|
+
# Micro::Case flow using `then` method
|
|
1296
|
+
# 6.968k i/100ms
|
|
1297
|
+
# Micro::Case flow using private methods
|
|
1298
|
+
# 10.362k i/100ms
|
|
1299
|
+
# Micro::Case flow using private methods through lambdas
|
|
1300
|
+
# 10.258k i/100ms
|
|
1293
1301
|
|
|
1294
1302
|
# Calculating -------------------------------------
|
|
1295
|
-
# Interactor::Organizer
|
|
1296
|
-
#
|
|
1297
|
-
# Micro::Cases
|
|
1298
|
-
#
|
|
1299
|
-
# Micro::
|
|
1303
|
+
# Interactor::Organizer
|
|
1304
|
+
# 50.731k (± 1.6%) i/s - 256.361k in 5.054694s
|
|
1305
|
+
# Micro::Cases.flow([])
|
|
1306
|
+
# 67.757k (± 1.6%) i/s - 344.505k in 5.085681s
|
|
1307
|
+
# Micro::Cases::safe_flow([])
|
|
1308
|
+
# 67.613k (± 1.6%) i/s - 340.450k in 5.036562s
|
|
1309
|
+
# Micro::Case flow using `then` method
|
|
1310
|
+
# 69.483k (± 1.5%) i/s - 348.400k in 5.015351s
|
|
1311
|
+
# Micro::Case flow using private methods
|
|
1312
|
+
# 103.788k (± 1.0%) i/s - 528.462k in 5.092240s
|
|
1313
|
+
# Micro::Case flow using private methods through lambdas
|
|
1314
|
+
# 101.081k (± 1.2%) i/s - 512.900k in 5.074904s
|
|
1300
1315
|
|
|
1301
1316
|
# Comparison:
|
|
1302
|
-
# Micro::Case flow using private methods:
|
|
1303
|
-
# Micro::Case flow using
|
|
1304
|
-
# Micro::
|
|
1305
|
-
# Micro::Cases
|
|
1306
|
-
#
|
|
1317
|
+
# Micro::Case flow using private methods: 103787.5 i/s
|
|
1318
|
+
# Micro::Case flow using private methods through lambdas: 101080.6 i/s - 1.03x (± 0.00) slower
|
|
1319
|
+
# Micro::Case flow using `then` method: 69483.3 i/s - 1.49x (± 0.00) slower
|
|
1320
|
+
# Micro::Cases.flow([]): 67757.2 i/s - 1.53x (± 0.00) slower
|
|
1321
|
+
# Micro::Cases::safe_flow([]): 67613.3 i/s - 1.54x (± 0.00) slower
|
|
1322
|
+
# Interactor::Organizer: 50730.8 i/s - 2.05x (± 0.00) slower
|
|
1307
1323
|
```
|
|
1308
1324
|
</details>
|
|
1309
1325
|
|
|
@@ -1312,25 +1328,39 @@ https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_failure_r
|
|
|
1312
1328
|
|
|
1313
1329
|
```ruby
|
|
1314
1330
|
# Warming up --------------------------------------
|
|
1315
|
-
# Interactor::Organizer
|
|
1316
|
-
#
|
|
1317
|
-
# Micro::Cases
|
|
1318
|
-
#
|
|
1319
|
-
# Micro::
|
|
1320
|
-
|
|
1331
|
+
# Interactor::Organizer
|
|
1332
|
+
# 2.299k i/100ms
|
|
1333
|
+
# Micro::Cases.flow([])
|
|
1334
|
+
# 14.187k i/100ms
|
|
1335
|
+
# Micro::Cases::safe_flow([])
|
|
1336
|
+
# 13.609k i/100ms
|
|
1337
|
+
# Micro::Case flow using `then` method
|
|
1338
|
+
# 14.578k i/100ms
|
|
1339
|
+
# Micro::Case flow using private methods
|
|
1340
|
+
# 14.101k i/100ms
|
|
1341
|
+
# Micro::Case flow using private methods through lambdas
|
|
1342
|
+
# 13.670k i/100ms
|
|
1321
1343
|
# Calculating -------------------------------------
|
|
1322
|
-
# Interactor::Organizer
|
|
1323
|
-
#
|
|
1324
|
-
# Micro::Cases
|
|
1325
|
-
#
|
|
1326
|
-
# Micro::
|
|
1344
|
+
# Interactor::Organizer
|
|
1345
|
+
# 23.306k (± 2.1%) i/s - 117.249k in 5.033171s
|
|
1346
|
+
# Micro::Cases.flow([])
|
|
1347
|
+
# 140.111k (± 1.6%) i/s - 709.350k in 5.064041s
|
|
1348
|
+
# Micro::Cases::safe_flow([])
|
|
1349
|
+
# 139.927k (± 1.7%) i/s - 707.668k in 5.058971s
|
|
1350
|
+
# Micro::Case flow using `then` method
|
|
1351
|
+
# 146.073k (± 2.0%) i/s - 743.478k in 5.091741s
|
|
1352
|
+
# Micro::Case flow using private methods
|
|
1353
|
+
# 142.092k (± 1.5%) i/s - 719.151k in 5.062298s
|
|
1354
|
+
# Micro::Case flow using private methods through lambdas
|
|
1355
|
+
# 140.791k (± 1.2%) i/s - 710.840k in 5.049584s
|
|
1327
1356
|
|
|
1328
1357
|
# Comparison:
|
|
1329
|
-
# Micro::Case flow using `then` method:
|
|
1330
|
-
# Micro::Case flow using private methods:
|
|
1331
|
-
# Micro::
|
|
1332
|
-
# Micro::Cases.flow([]):
|
|
1333
|
-
#
|
|
1358
|
+
# Micro::Case flow using `then` method: 146073.0 i/s
|
|
1359
|
+
# Micro::Case flow using private methods: 142091.7 i/s - same-ish: difference falls within error
|
|
1360
|
+
# Micro::Case flow using private methods through lambdas: 140791.1 i/s - 1.04x (± 0.00) slower
|
|
1361
|
+
# Micro::Cases.flow([]): 140110.8 i/s - 1.04x (± 0.00) slower
|
|
1362
|
+
# Micro::Cases::safe_flow([]): 139926.6 i/s - 1.04x (± 0.00) slower
|
|
1363
|
+
# Interactor::Organizer: 23305.9 i/s - 6.27x (± 0.00) slower
|
|
1334
1364
|
```
|
|
1335
1365
|
</details>
|
|
1336
1366
|
|
|
@@ -1347,24 +1377,24 @@ Confira as implementações do mesmo caso de uso com diferentes gems/abstraçõe
|
|
|
1347
1377
|
|
|
1348
1378
|
## Exemplos
|
|
1349
1379
|
|
|
1350
|
-
### 1️⃣
|
|
1380
|
+
### 1️⃣ Criação de usuários
|
|
1381
|
+
|
|
1382
|
+
> Um exemplo de fluxo que define etapas para higienizar, validar e persistir seus dados de entrada. Ele tem todas as abordagens possíveis para representar casos de uso com a gem `u-case`.
|
|
1383
|
+
>
|
|
1384
|
+
> Link: https://github.com/serradura/u-case/blob/main/examples/users_creation
|
|
1385
|
+
|
|
1386
|
+
### 2️⃣ Rails App (API)
|
|
1351
1387
|
|
|
1352
1388
|
> Este projeto mostra diferentes tipos de arquitetura (uma por commit), e na última, como usar a gem `Micro::Case` para lidar com a lógica de negócios da aplicação.
|
|
1353
1389
|
>
|
|
1354
1390
|
> Link: https://github.com/serradura/from-fat-controllers-to-use-cases
|
|
1355
1391
|
|
|
1356
|
-
###
|
|
1392
|
+
### 3️⃣ CLI calculator
|
|
1357
1393
|
|
|
1358
1394
|
> Rake tasks para demonstrar como lidar com os dados do usuário e como usar diferentes tipos de falha para controlar o fluxo do programa.
|
|
1359
1395
|
>
|
|
1360
1396
|
> Link: https://github.com/serradura/u-case/tree/main/examples/calculator
|
|
1361
1397
|
|
|
1362
|
-
### 3️⃣ Criação de usuários
|
|
1363
|
-
|
|
1364
|
-
> Um exemplo de fluxo de caso de uso que define etapas para higienizar, validar e persistir seus dados de entrada.
|
|
1365
|
-
>
|
|
1366
|
-
> Link: https://github.com/serradura/u-case/blob/main/examples/users_creation.rb
|
|
1367
|
-
|
|
1368
1398
|
### 4️⃣ Interceptando exceções dentro dos casos de uso
|
|
1369
1399
|
|
|
1370
1400
|
> Link: https://github.com/serradura/u-case/blob/main/examples/rescuing_exceptions.rb
|
data/lib/micro/case.rb
CHANGED
|
@@ -72,9 +72,7 @@ module Micro
|
|
|
72
72
|
def self.__new__(result, arg)
|
|
73
73
|
input = result.__set_transitions_accessible_attributes__(arg)
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
instance.__set_result__(result)
|
|
77
|
-
instance
|
|
75
|
+
new(input).__set_result__(result)
|
|
78
76
|
end
|
|
79
77
|
|
|
80
78
|
def self.__flow_builder__
|
|
@@ -135,6 +133,8 @@ module Micro
|
|
|
135
133
|
raise Error::ResultIsAlreadyDefined if defined?(@__result)
|
|
136
134
|
|
|
137
135
|
@__result = result
|
|
136
|
+
|
|
137
|
+
self
|
|
138
138
|
end
|
|
139
139
|
|
|
140
140
|
private
|
data/lib/micro/case/config.rb
CHANGED
data/lib/micro/case/result.rb
CHANGED
|
@@ -7,7 +7,11 @@ module Micro
|
|
|
7
7
|
class Result
|
|
8
8
|
Kind::Types.add(self)
|
|
9
9
|
|
|
10
|
-
@@
|
|
10
|
+
@@transitions_enabled = true
|
|
11
|
+
|
|
12
|
+
def self.transitions_enabled?
|
|
13
|
+
@@transitions_enabled
|
|
14
|
+
end
|
|
11
15
|
|
|
12
16
|
attr_reader :type, :data, :use_case
|
|
13
17
|
|
|
@@ -142,19 +146,21 @@ module Micro
|
|
|
142
146
|
|
|
143
147
|
@__transitions_accumulated_data.merge!(@data)
|
|
144
148
|
|
|
145
|
-
|
|
149
|
+
use_case_attributes = Utils.symbolize_hash_keys(@use_case.attributes)
|
|
150
|
+
|
|
151
|
+
__update_transitions_accessible_attributes(use_case_attributes)
|
|
152
|
+
|
|
153
|
+
__set_transition(use_case_attributes) if @@transitions_enabled
|
|
146
154
|
|
|
147
155
|
self
|
|
148
156
|
end
|
|
149
157
|
|
|
150
158
|
def __set_transitions_accessible_attributes__(arg)
|
|
151
|
-
return arg unless
|
|
159
|
+
return arg unless arg.is_a?(Hash)
|
|
152
160
|
|
|
153
|
-
|
|
154
|
-
attributes = Utils.symbolize_hash_keys(arg)
|
|
161
|
+
attributes = Utils.symbolize_hash_keys(arg)
|
|
155
162
|
|
|
156
|
-
|
|
157
|
-
end
|
|
163
|
+
__update_transitions_accessible_attributes(attributes)
|
|
158
164
|
end
|
|
159
165
|
|
|
160
166
|
private
|
|
@@ -165,7 +171,9 @@ module Micro
|
|
|
165
171
|
opt ? opt.merge(@__transitions_accumulated_data) : @__transitions_accumulated_data
|
|
166
172
|
)
|
|
167
173
|
|
|
168
|
-
|
|
174
|
+
return fn.call if fn.arity.zero?
|
|
175
|
+
|
|
176
|
+
opt ? fn.call(**input) : fn.call(input)
|
|
169
177
|
end
|
|
170
178
|
|
|
171
179
|
def __call_proc(fn, expected)
|
|
@@ -197,11 +205,8 @@ module Micro
|
|
|
197
205
|
@__transitions_accessible_attributes
|
|
198
206
|
end
|
|
199
207
|
|
|
200
|
-
def __set_transition
|
|
208
|
+
def __set_transition(use_case_attributes)
|
|
201
209
|
use_case_class = @use_case.class
|
|
202
|
-
use_case_attributes = Utils.symbolize_hash_keys(@use_case.attributes)
|
|
203
|
-
|
|
204
|
-
__update_transitions_accessible_attributes(use_case_attributes)
|
|
205
210
|
|
|
206
211
|
result = @success ? :success : :failure
|
|
207
212
|
|
data/lib/micro/case/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: u-case
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.0.0.
|
|
4
|
+
version: 3.0.0.rc8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rodrigo Serradura
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-08-
|
|
11
|
+
date: 2020-08-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: kind
|