u-case 3.1.0 → 4.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.sh +30 -10
- data/Gemfile +20 -9
- data/README.md +160 -134
- data/README.pt-BR.md +161 -136
- data/lib/micro/case.rb +68 -15
- data/lib/micro/case/error.rb +4 -1
- data/lib/micro/case/result.rb +42 -8
- data/lib/micro/case/result/transitions.rb +1 -4
- data/lib/micro/case/result/wrapper.rb +45 -0
- data/lib/micro/case/safe.rb +1 -1
- data/lib/micro/case/strict.rb +2 -2
- data/lib/micro/case/utils.rb +19 -10
- data/lib/micro/case/version.rb +1 -1
- data/lib/micro/cases.rb +7 -0
- data/lib/micro/cases/error.rb +13 -0
- data/lib/micro/cases/flow.rb +23 -14
- data/lib/micro/cases/map.rb +39 -0
- data/lib/micro/cases/safe/flow.rb +2 -2
- data/lib/micro/cases/utils.rb +21 -0
- data/u-case.gemspec +3 -3
- metadata +12 -6
data/README.pt-BR.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
<p align="center">
|
2
|
-
<img src="./assets/ucase_logo_v1.png" alt="u-case -
|
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.">
|
3
3
|
|
4
|
-
<p align="center"><i>
|
4
|
+
<p align="center"><i> Represente casos de uso de forma simples e poderosa ao escrever código modular, expressivo e sequencialmente lógico.</i></p>
|
5
5
|
<br>
|
6
6
|
</p>
|
7
7
|
|
@@ -38,7 +38,9 @@ Principais objetivos deste projeto:
|
|
38
38
|
|
39
39
|
Versão | Documentação
|
40
40
|
--------- | -------------
|
41
|
-
|
41
|
+
unreleased| https://github.com/serradura/u-case/blob/main/README.md
|
42
|
+
4.2.1 | https://github.com/serradura/u-case/blob/v4.x/README.md
|
43
|
+
3.1.0 | https://github.com/serradura/u-case/blob/v3.x/README.md
|
42
44
|
2.6.0 | https://github.com/serradura/u-case/blob/v2.x/README.md
|
43
45
|
1.1.0 | https://github.com/serradura/u-case/blob/v1.x/README.md
|
44
46
|
|
@@ -80,6 +82,9 @@ Versão | Documentação
|
|
80
82
|
- [Success results](#success-results)
|
81
83
|
- [Failure results](#failure-results)
|
82
84
|
- [`Micro::Cases::Flow`](#microcasesflow)
|
85
|
+
- [Execuntando os benchmarks](#execuntando-os-benchmarks)
|
86
|
+
- [Performance (Benchmarks IPS)](#performance-benchmarks-ips)
|
87
|
+
- [Memory profiling](#memory-profiling)
|
83
88
|
- [Comparações](#comparações)
|
84
89
|
- [Exemplos](#exemplos)
|
85
90
|
- [1️⃣ Criação de usuários](#1️⃣-criação-de-usuários)
|
@@ -93,11 +98,12 @@ Versão | Documentação
|
|
93
98
|
|
94
99
|
## Compatibilidade
|
95
100
|
|
96
|
-
| u-case | branch | ruby | activemodel |
|
97
|
-
| -------------- | ------- | -------- | ------------- |
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
| u-case | branch | ruby | activemodel | u-attributes |
|
102
|
+
| -------------- | ------- | -------- | ------------- | ------------ |
|
103
|
+
| 4.2.1 | 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 |
|
101
107
|
|
102
108
|
> Nota: O activemodel é uma dependência opcional, esse módulo que [pode ser habilitado](#u-casewith_activemodel_validation---como-validar-os-atributos-do-caso-de-uso) para validar os atributos dos casos de uso.
|
103
109
|
|
@@ -118,7 +124,7 @@ Versão | Documentação
|
|
118
124
|
Adicione essa linha ao Gemfile da sua aplicação:
|
119
125
|
|
120
126
|
```ruby
|
121
|
-
gem 'u-case', '~>
|
127
|
+
gem 'u-case', '~> 4.1.0'
|
122
128
|
```
|
123
129
|
|
124
130
|
E então execute:
|
@@ -127,7 +133,7 @@ E então execute:
|
|
127
133
|
|
128
134
|
Ou instale manualmente:
|
129
135
|
|
130
|
-
$ gem install u-case
|
136
|
+
$ gem install u-case
|
131
137
|
|
132
138
|
## Uso
|
133
139
|
|
@@ -1195,106 +1201,108 @@ end
|
|
1195
1201
|
|
1196
1202
|
#### Success results
|
1197
1203
|
|
1198
|
-
| Gem / Abstração | Iterações por segundo |
|
1199
|
-
| ----------------- | --------------------: |
|
1200
|
-
| Dry::Monads |
|
1201
|
-
| **Micro::Case** |
|
1202
|
-
| Interactor |
|
1203
|
-
| Trailblazer::Operation |
|
1204
|
-
| Dry::Transaction |
|
1204
|
+
| Gem / Abstração | Iterações por segundo | Comparação |
|
1205
|
+
| ----------------- | --------------------: | -------------------: |
|
1206
|
+
| Dry::Monads | 315635.1 | _**O mais rápido**_ |
|
1207
|
+
| **Micro::Case** | 75837.7 | 4.16x mais lento |
|
1208
|
+
| Interactor | 59745.5 | 5.28x mais lento |
|
1209
|
+
| Trailblazer::Operation | 28423.9 | 11.10x mais lento |
|
1210
|
+
| Dry::Transaction | 10130.9 | 31.16x mais lento |
|
1205
1211
|
|
1206
1212
|
<details>
|
1207
1213
|
<summary>Show the full <a href="https://github.com/evanphx/benchmark-ips">benchmark/ips</a> results.</summary>
|
1208
1214
|
|
1209
1215
|
```ruby
|
1210
1216
|
# Warming up --------------------------------------
|
1211
|
-
# Interactor
|
1212
|
-
# Trailblazer::Operation
|
1213
|
-
#
|
1214
|
-
#
|
1215
|
-
#
|
1216
|
-
#
|
1217
|
-
# Micro::Case::Safe
|
1217
|
+
# Interactor 5.711k i/100ms
|
1218
|
+
# Trailblazer::Operation
|
1219
|
+
# 2.283k i/100ms
|
1220
|
+
# Dry::Monads 31.130k i/100ms
|
1221
|
+
# Dry::Transaction 994.000 i/100ms
|
1222
|
+
# Micro::Case 7.911k i/100ms
|
1223
|
+
# Micro::Case::Safe 7.911k i/100ms
|
1224
|
+
# Micro::Case::Strict 6.248k i/100ms
|
1218
1225
|
|
1219
1226
|
# Calculating -------------------------------------
|
1220
|
-
# Interactor
|
1221
|
-
# Trailblazer::Operation
|
1222
|
-
#
|
1223
|
-
#
|
1224
|
-
#
|
1225
|
-
#
|
1226
|
-
# Micro::Case::Safe
|
1227
|
+
# Interactor 59.746k (±29.9%) i/s - 274.128k in 5.049901s
|
1228
|
+
# Trailblazer::Operation
|
1229
|
+
# 28.424k (±15.8%) i/s - 141.546k in 5.087882s
|
1230
|
+
# Dry::Monads 315.635k (± 6.1%) i/s - 1.588M in 5.048914s
|
1231
|
+
# Dry::Transaction 10.131k (± 6.4%) i/s - 50.694k in 5.025150s
|
1232
|
+
# Micro::Case 75.838k (± 9.7%) i/s - 379.728k in 5.052573s
|
1233
|
+
# Micro::Case::Safe 75.461k (±10.1%) i/s - 379.728k in 5.079238s
|
1234
|
+
# Micro::Case::Strict 64.235k (± 9.0%) i/s - 324.896k in 5.097028s
|
1227
1235
|
|
1228
1236
|
# Comparison:
|
1229
|
-
# Dry::Monads:
|
1230
|
-
# Micro::Case:
|
1231
|
-
# Micro::Case::Safe:
|
1232
|
-
# Micro::Case::Strict:
|
1233
|
-
# Interactor:
|
1234
|
-
# Trailblazer::Operation:
|
1235
|
-
# Dry::Transaction:
|
1237
|
+
# Dry::Monads: 315635.1 i/s
|
1238
|
+
# Micro::Case: 75837.7 i/s - 4.16x (± 0.00) slower
|
1239
|
+
# Micro::Case::Safe: 75461.3 i/s - 4.18x (± 0.00) slower
|
1240
|
+
# Micro::Case::Strict: 64234.9 i/s - 4.91x (± 0.00) slower
|
1241
|
+
# Interactor: 59745.5 i/s - 5.28x (± 0.00) slower
|
1242
|
+
# Trailblazer::Operation: 28423.9 i/s - 11.10x (± 0.00) slower
|
1243
|
+
# Dry::Transaction: 10130.9 i/s - 31.16x (± 0.00) slower
|
1236
1244
|
```
|
1237
1245
|
</details>
|
1238
1246
|
|
1239
|
-
https://github.com/serradura/u-case/blob/main/benchmarks/use_case/
|
1247
|
+
https://github.com/serradura/u-case/blob/main/benchmarks/perfomance/use_case/success_results.
|
1240
1248
|
|
1241
1249
|
#### Failure results
|
1242
1250
|
|
1243
|
-
| Gem / Abstração | Iterações por segundo |
|
1244
|
-
| ----------------- | --------------------: |
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
| Trailblazer::Operation |
|
1248
|
-
| Interactor |
|
1249
|
-
| Dry::Transaction |
|
1251
|
+
| Gem / Abstração | Iterações por segundo | Comparação |
|
1252
|
+
| ----------------- | --------------------: | -------------------: |
|
1253
|
+
| Dry::Monads | 135386.9 | _**O mais rápido**_ |
|
1254
|
+
| **Micro::Case** | 73489.3 | 1.85x mais lento |
|
1255
|
+
| Trailblazer::Operation | 29016.4 | 4.67x mais lento |
|
1256
|
+
| Interactor | 27037.0 | 5.01x mais lento |
|
1257
|
+
| Dry::Transaction | 8988.6 | 15.06x mais lento |
|
1250
1258
|
|
1251
1259
|
<details>
|
1252
1260
|
<summary>Mostrar o resultado completo do <a href="https://github.com/evanphx/benchmark-ips">benchmark/ips</a>.</summary>
|
1253
1261
|
|
1254
1262
|
```ruby
|
1255
1263
|
# Warming up --------------------------------------
|
1256
|
-
# Interactor
|
1257
|
-
# Trailblazer::Operation
|
1258
|
-
# Dry::Monads
|
1259
|
-
# Dry::Transaction
|
1260
|
-
# Micro::Case
|
1261
|
-
#
|
1262
|
-
#
|
1264
|
+
# Interactor 2.626k i/100ms
|
1265
|
+
# Trailblazer::Operation 2.343k i/100ms
|
1266
|
+
# Dry::Monads 13.386k i/100ms
|
1267
|
+
# Dry::Transaction 868.000 i/100ms
|
1268
|
+
# Micro::Case 7.603k i/100ms
|
1269
|
+
# Micro::Case::Safe 7.598k i/100ms
|
1270
|
+
# Micro::Case::Strict 6.178k i/100ms
|
1263
1271
|
|
1264
1272
|
# Calculating -------------------------------------
|
1265
|
-
# Interactor
|
1266
|
-
# Trailblazer::Operation
|
1267
|
-
# Dry::Monads
|
1268
|
-
# Dry::Transaction
|
1269
|
-
# Micro::Case
|
1270
|
-
#
|
1271
|
-
#
|
1273
|
+
# Interactor 27.037k (±24.9%) i/s - 128.674k in 5.102133s
|
1274
|
+
# Trailblazer::Operation 29.016k (±12.4%) i/s - 145.266k in 5.074991s
|
1275
|
+
# Dry::Monads 135.387k (±15.1%) i/s - 669.300k in 5.055356s
|
1276
|
+
# Dry::Transaction 8.989k (± 9.2%) i/s - 45.136k in 5.084820s
|
1277
|
+
# Micro::Case 73.247k (± 9.9%) i/s - 364.944k in 5.030449s
|
1278
|
+
# Micro::Case::Safe 73.489k (± 9.6%) i/s - 364.704k in 5.007282s
|
1279
|
+
# Micro::Case::Strict 61.980k (± 8.0%) i/s - 308.900k in 5.014821s
|
1272
1280
|
|
1273
1281
|
# Comparison:
|
1274
|
-
#
|
1275
|
-
# Micro::Case::Safe:
|
1276
|
-
#
|
1277
|
-
#
|
1278
|
-
# Trailblazer::Operation:
|
1279
|
-
# Interactor:
|
1280
|
-
# Dry::Transaction:
|
1282
|
+
# Dry::Monads: 135386.9 i/s
|
1283
|
+
# Micro::Case::Safe: 73489.3 i/s - 1.84x (± 0.00) slower
|
1284
|
+
# Micro::Case: 73246.6 i/s - 1.85x (± 0.00) slower
|
1285
|
+
# Micro::Case::Strict: 61979.7 i/s - 2.18x (± 0.00) slower
|
1286
|
+
# Trailblazer::Operation: 29016.4 i/s - 4.67x (± 0.00) slower
|
1287
|
+
# Interactor: 27037.0 i/s - 5.01x (± 0.00) slower
|
1288
|
+
# Dry::Transaction: 8988.6 i/s - 15.06x (± 0.00) slower
|
1281
1289
|
```
|
1282
1290
|
</details>
|
1283
1291
|
|
1284
|
-
https://github.com/serradura/u-case/blob/main/benchmarks/use_case/
|
1292
|
+
https://github.com/serradura/u-case/blob/main/benchmarks/perfomance/use_case/failure_results.
|
1285
1293
|
|
1286
1294
|
---
|
1287
1295
|
|
1288
1296
|
### `Micro::Cases::Flow`
|
1289
1297
|
|
1290
|
-
| Gem / Abstração | [Resultados de sucesso](https://github.com/serradura/u-case/blob/main/benchmarks/flow/
|
1298
|
+
| Gem / Abstração | [Resultados de sucesso](https://github.com/serradura/u-case/blob/main/benchmarks/perfomance/flow/success_results.rb) | [Resultados de falha](https://github.com/serradura/u-case/blob/main/benchmarks/perfomance/flow/failure_results.rb) |
|
1291
1299
|
| ------------------------------------------- | ----------------: | ----------------: |
|
1292
|
-
| Micro::Case
|
1293
|
-
| Micro::Case
|
1294
|
-
| Micro::
|
1295
|
-
| Micro::
|
1296
|
-
| Micro::
|
1297
|
-
| Interactor::Organizer |
|
1300
|
+
| Micro::Case::Result `pipe` method | 80936.2 i/s | 78280.4 i/s |
|
1301
|
+
| Micro::Case::Result `then` method | 0x mais lento | 0x mais lento |
|
1302
|
+
| Micro::Cases.flow | 0x mais lento | 0x mais lento |
|
1303
|
+
| Micro::Case class with an inner flow | 1.72x mais lento | 1.68x mais lento |
|
1304
|
+
| Micro::Case class including itself as a step| 1.93x mais lento | 1.87x mais lento |
|
1305
|
+
| Interactor::Organizer | 3.33x mais lento | 3.22x mais lento |
|
1298
1306
|
|
1299
1307
|
\* As gems `Dry::Monads`, `Dry::Transaction`, `Trailblazer::Operation` estão fora desta análise por não terem esse tipo de funcionalidade.
|
1300
1308
|
|
@@ -1303,40 +1311,28 @@ https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_failure_r
|
|
1303
1311
|
|
1304
1312
|
```ruby
|
1305
1313
|
# Warming up --------------------------------------
|
1306
|
-
# Interactor::Organizer
|
1307
|
-
#
|
1308
|
-
# Micro::
|
1309
|
-
#
|
1310
|
-
# Micro::
|
1311
|
-
#
|
1312
|
-
# Micro::Case flow using `then` method
|
1313
|
-
# 6.968k i/100ms
|
1314
|
-
# Micro::Case flow using private methods
|
1315
|
-
# 10.362k i/100ms
|
1316
|
-
# Micro::Case flow using private methods through lambdas
|
1317
|
-
# 10.258k i/100ms
|
1314
|
+
# Interactor::Organizer 1.809k i/100ms
|
1315
|
+
# Micro::Cases.flow([]) 7.808k i/100ms
|
1316
|
+
# Micro::Case flow in a class 4.816k i/100ms
|
1317
|
+
# Micro::Case including the class 4.094k i/100ms
|
1318
|
+
# Micro::Case::Result#| 7.656k i/100ms
|
1319
|
+
# Micro::Case::Result#then 7.138k i/100ms
|
1318
1320
|
|
1319
1321
|
# Calculating -------------------------------------
|
1320
|
-
# Interactor::Organizer
|
1321
|
-
#
|
1322
|
-
# Micro::
|
1323
|
-
#
|
1324
|
-
# Micro::
|
1325
|
-
#
|
1326
|
-
# Micro::Case flow using `then` method
|
1327
|
-
# 69.483k (± 1.5%) i/s - 348.400k in 5.015351s
|
1328
|
-
# Micro::Case flow using private methods
|
1329
|
-
# 103.788k (± 1.0%) i/s - 528.462k in 5.092240s
|
1330
|
-
# Micro::Case flow using private methods through lambdas
|
1331
|
-
# 101.081k (± 1.2%) i/s - 512.900k in 5.074904s
|
1322
|
+
# Interactor::Organizer 24.290k (±24.0%) i/s - 113.967k in 5.032825s
|
1323
|
+
# Micro::Cases.flow([]) 74.790k (±11.1%) i/s - 374.784k in 5.071740s
|
1324
|
+
# Micro::Case flow in a class 47.043k (± 8.0%) i/s - 235.984k in 5.047477s
|
1325
|
+
# Micro::Case including the class 42.030k (± 8.5%) i/s - 208.794k in 5.002138s
|
1326
|
+
# Micro::Case::Result#| 80.936k (±15.9%) i/s - 398.112k in 5.052531s
|
1327
|
+
# Micro::Case::Result#then 71.459k (± 8.8%) i/s - 356.900k in 5.030526s
|
1332
1328
|
|
1333
1329
|
# Comparison:
|
1334
|
-
# Micro::Case
|
1335
|
-
# Micro::
|
1336
|
-
# Micro::Case
|
1337
|
-
# Micro::
|
1338
|
-
# Micro::
|
1339
|
-
# Interactor::Organizer:
|
1330
|
+
# Micro::Case::Result#|: 80936.2 i/s
|
1331
|
+
# Micro::Cases.flow([]): 74790.1 i/s - same-ish: difference falls within error
|
1332
|
+
# Micro::Case::Result#then: 71459.5 i/s - same-ish: difference falls within error
|
1333
|
+
# Micro::Case flow in a class: 47042.6 i/s - 1.72x (± 0.00) slower
|
1334
|
+
# Micro::Case including the class: 42030.2 i/s - 1.93x (± 0.00) slower
|
1335
|
+
# Interactor::Organizer: 24290.3 i/s - 3.33x (± 0.00) slower
|
1340
1336
|
```
|
1341
1337
|
</details>
|
1342
1338
|
|
@@ -1345,43 +1341,72 @@ https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_failure_r
|
|
1345
1341
|
|
1346
1342
|
```ruby
|
1347
1343
|
# Warming up --------------------------------------
|
1348
|
-
# Interactor::Organizer
|
1349
|
-
#
|
1350
|
-
# Micro::
|
1351
|
-
#
|
1352
|
-
# Micro::
|
1353
|
-
#
|
1354
|
-
|
1355
|
-
# 14.578k i/100ms
|
1356
|
-
# Micro::Case flow using private methods
|
1357
|
-
# 14.101k i/100ms
|
1358
|
-
# Micro::Case flow using private methods through lambdas
|
1359
|
-
# 13.670k i/100ms
|
1344
|
+
# Interactor::Organizer 1.734k i/100ms
|
1345
|
+
# Micro::Cases.flow([]) 7.515k i/100ms
|
1346
|
+
# Micro::Case flow in a class 4.636k i/100ms
|
1347
|
+
# Micro::Case including the class 4.114k i/100ms
|
1348
|
+
# Micro::Case::Result#| 7.588k i/100ms
|
1349
|
+
# Micro::Case::Result#then 6.681k i/100ms
|
1350
|
+
|
1360
1351
|
# Calculating -------------------------------------
|
1361
|
-
# Interactor::Organizer
|
1362
|
-
#
|
1363
|
-
# Micro::
|
1364
|
-
#
|
1365
|
-
# Micro::
|
1366
|
-
#
|
1367
|
-
# Micro::Case flow using `then` method
|
1368
|
-
# 146.073k (± 2.0%) i/s - 743.478k in 5.091741s
|
1369
|
-
# Micro::Case flow using private methods
|
1370
|
-
# 142.092k (± 1.5%) i/s - 719.151k in 5.062298s
|
1371
|
-
# Micro::Case flow using private methods through lambdas
|
1372
|
-
# 140.791k (± 1.2%) i/s - 710.840k in 5.049584s
|
1352
|
+
# Interactor::Organizer 24.280k (±24.5%) i/s - 112.710k in 5.013334s
|
1353
|
+
# Micro::Cases.flow([]) 74.999k (± 9.8%) i/s - 375.750k in 5.055777s
|
1354
|
+
# Micro::Case flow in a class 46.681k (± 9.3%) i/s - 236.436k in 5.105105s
|
1355
|
+
# Micro::Case including the class 41.921k (± 8.9%) i/s - 209.814k in 5.043622s
|
1356
|
+
# Micro::Case::Result#| 78.280k (±12.6%) i/s - 386.988k in 5.022146s
|
1357
|
+
# Micro::Case::Result#then 68.898k (± 8.8%) i/s - 347.412k in 5.080116s
|
1373
1358
|
|
1374
1359
|
# Comparison:
|
1375
|
-
# Micro::Case
|
1376
|
-
# Micro::
|
1377
|
-
# Micro::Case
|
1378
|
-
# Micro::
|
1379
|
-
# Micro::
|
1380
|
-
# Interactor::Organizer:
|
1360
|
+
# Micro::Case::Result#|: 78280.4 i/s
|
1361
|
+
# Micro::Cases.flow([]): 74999.4 i/s - same-ish: difference falls within error
|
1362
|
+
# Micro::Case::Result#then: 68898.4 i/s - same-ish: difference falls within error
|
1363
|
+
# Micro::Case flow in a class: 46681.0 i/s - 1.68x (± 0.00) slower
|
1364
|
+
# Micro::Case including the class: 41920.8 i/s - 1.87x (± 0.00) slower
|
1365
|
+
# Interactor::Organizer: 24280.0 i/s - 3.22x (± 0.00) slower
|
1381
1366
|
```
|
1382
1367
|
</details>
|
1383
1368
|
|
1384
|
-
https://github.com/serradura/u-case/
|
1369
|
+
https://github.com/serradura/u-case/blob/main/benchmarks/perfomance/flow/
|
1370
|
+
|
1371
|
+
[⬆️ Voltar para o índice](#índice-)
|
1372
|
+
|
1373
|
+
### Execuntando os benchmarks
|
1374
|
+
|
1375
|
+
#### Performance (Benchmarks IPS)
|
1376
|
+
|
1377
|
+
Clone este repositório e acesse a sua pasta, então execute os comandos abaixo:
|
1378
|
+
|
1379
|
+
**Casos de uso**
|
1380
|
+
|
1381
|
+
```sh
|
1382
|
+
ruby benchmarks/perfomance/use_case/failure_results.rb
|
1383
|
+
ruby benchmarks/perfomance/use_case/success_results.rb
|
1384
|
+
```
|
1385
|
+
|
1386
|
+
**Flows**
|
1387
|
+
|
1388
|
+
```sh
|
1389
|
+
ruby benchmarks/perfomance/flow/failure_results.rb
|
1390
|
+
ruby benchmarks/perfomance/flow/success_results.rb
|
1391
|
+
```
|
1392
|
+
|
1393
|
+
#### Memory profiling
|
1394
|
+
|
1395
|
+
**Casos de uso**
|
1396
|
+
|
1397
|
+
```sh
|
1398
|
+
./benchmarks/memory/use_case/success/with_transitions/analyze.sh
|
1399
|
+
./benchmarks/memory/use_case/success/without_transitions/analyze.sh
|
1400
|
+
```
|
1401
|
+
|
1402
|
+
**Flows**
|
1403
|
+
|
1404
|
+
```sh
|
1405
|
+
./benchmarks/memory/flow/success/with_transitions/analyze.sh
|
1406
|
+
./benchmarks/memory/flow/success/without_transitions/analyze.sh
|
1407
|
+
```
|
1408
|
+
|
1409
|
+
[⬆️ Voltar para o índice](#índice-)
|
1385
1410
|
|
1386
1411
|
### Comparações
|
1387
1412
|
|
data/lib/micro/case.rb
CHANGED
@@ -7,6 +7,7 @@ require 'micro/case/version'
|
|
7
7
|
|
8
8
|
module Micro
|
9
9
|
class Case
|
10
|
+
require 'micro/cases/utils'
|
10
11
|
require 'micro/case/utils'
|
11
12
|
require 'micro/case/error'
|
12
13
|
require 'micro/case/result'
|
@@ -16,10 +17,14 @@ module Micro
|
|
16
17
|
|
17
18
|
require 'micro/cases'
|
18
19
|
|
19
|
-
include Micro::Attributes
|
20
|
+
include Micro::Attributes
|
20
21
|
|
21
|
-
def self.call(
|
22
|
-
new
|
22
|
+
def self.call(input = Kind::Empty::HASH)
|
23
|
+
result = __new__(Result.new, input).__call__
|
24
|
+
|
25
|
+
return result unless block_given?
|
26
|
+
|
27
|
+
yield Result::Wrapper.new(result)
|
23
28
|
end
|
24
29
|
|
25
30
|
INVALID_INVOCATION_OF_THE_THEN_METHOD =
|
@@ -47,7 +52,7 @@ module Micro
|
|
47
52
|
end
|
48
53
|
|
49
54
|
def self.flow(*args)
|
50
|
-
@__flow_use_cases = args
|
55
|
+
@__flow_use_cases = Cases::Utils.map_use_cases(args)
|
51
56
|
end
|
52
57
|
|
53
58
|
class << self
|
@@ -63,7 +68,8 @@ module Micro
|
|
63
68
|
end
|
64
69
|
|
65
70
|
def self.inherited(subclass)
|
66
|
-
subclass.
|
71
|
+
subclass.__attributes_set_after_inherit__(self.__attributes_data__)
|
72
|
+
|
67
73
|
subclass.extend ::Micro::Attributes.const_get('Macros::ForSubclasses'.freeze)
|
68
74
|
|
69
75
|
if self.send(:__flow_use_cases) && !subclass.name.to_s.end_with?(FLOW_STEP)
|
@@ -80,6 +86,8 @@ module Micro
|
|
80
86
|
new(input).__set_result__(result)
|
81
87
|
end
|
82
88
|
|
89
|
+
private_class_method :new
|
90
|
+
|
83
91
|
def self.__flow_builder__
|
84
92
|
Cases::Flow
|
85
93
|
end
|
@@ -121,6 +129,28 @@ module Micro
|
|
121
129
|
__flow_set(__flow_use_cases_get) if !__flow_get__ && __flow_use_cases
|
122
130
|
end
|
123
131
|
|
132
|
+
InspectKey = :__inspect_key__ # :nodoc:
|
133
|
+
|
134
|
+
def self.inspect
|
135
|
+
ids = (Thread.current[InspectKey] ||= [])
|
136
|
+
|
137
|
+
if ids.include?(object_id)
|
138
|
+
return sprintf('#<%s: ...>', self)
|
139
|
+
end
|
140
|
+
|
141
|
+
begin
|
142
|
+
ids << object_id
|
143
|
+
|
144
|
+
if __flow_use_cases
|
145
|
+
return '<%s (%s) use_cases=%s>' % [self, __flow_builder__, @__flow_use_cases]
|
146
|
+
else
|
147
|
+
return '<%s (%s) attributes=%s>' % [self, self.superclass, attributes]
|
148
|
+
end
|
149
|
+
ensure
|
150
|
+
ids.pop
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
124
154
|
def initialize(input)
|
125
155
|
__setup_use_case(input)
|
126
156
|
end
|
@@ -130,7 +160,7 @@ module Micro
|
|
130
160
|
end
|
131
161
|
|
132
162
|
def __call__
|
133
|
-
|
163
|
+
__call_the_use_case_or_its_flow
|
134
164
|
end
|
135
165
|
|
136
166
|
def __set_result__(result)
|
@@ -144,12 +174,21 @@ module Micro
|
|
144
174
|
|
145
175
|
private
|
146
176
|
|
177
|
+
def call(use_case, defaults = Kind::Empty::HASH)
|
178
|
+
raise Error::InvalidUseCase unless ::Micro.case_or_flow?(use_case)
|
179
|
+
|
180
|
+
input =
|
181
|
+
defaults.empty? ? attributes : attributes.merge(Utils::Hashes.stringify_keys(defaults))
|
182
|
+
|
183
|
+
use_case.__new__(@__result, input).__call__
|
184
|
+
end
|
185
|
+
|
147
186
|
def apply(name)
|
148
187
|
method(name)
|
149
188
|
end
|
150
189
|
|
151
|
-
def
|
152
|
-
return
|
190
|
+
def __call_the_use_case_or_its_flow
|
191
|
+
return __call_the_use_case_flow if __call_the_use_case_flow?
|
153
192
|
|
154
193
|
__call_use_case
|
155
194
|
end
|
@@ -170,11 +209,11 @@ module Micro
|
|
170
209
|
raise Error::UnexpectedResult.new("#{self.class.name}#call!")
|
171
210
|
end
|
172
211
|
|
173
|
-
def
|
212
|
+
def __call_the_use_case_flow?
|
174
213
|
self.class.__flow_get__
|
175
214
|
end
|
176
215
|
|
177
|
-
def
|
216
|
+
def __call_the_use_case_flow
|
178
217
|
self.class.__flow_get__.call(@__input)
|
179
218
|
end
|
180
219
|
|
@@ -200,18 +239,32 @@ module Micro
|
|
200
239
|
__get_result(false, value, type)
|
201
240
|
end
|
202
241
|
|
203
|
-
def
|
204
|
-
@__result
|
242
|
+
def __get_result(is_success, value, type)
|
243
|
+
@__result.__set__(is_success, value, type, self)
|
205
244
|
end
|
206
245
|
|
207
|
-
def
|
208
|
-
|
246
|
+
def transaction(adapter = :activerecord)
|
247
|
+
raise NotImplementedError unless adapter == :activerecord
|
248
|
+
|
249
|
+
result = nil
|
250
|
+
|
251
|
+
ActiveRecord::Base.transaction do
|
252
|
+
result = yield
|
253
|
+
|
254
|
+
raise ActiveRecord::Rollback if result.failure?
|
255
|
+
end
|
256
|
+
|
257
|
+
result
|
209
258
|
end
|
210
259
|
|
211
260
|
private_constant :MapFailureType, :INVALID_INVOCATION_OF_THE_THEN_METHOD
|
212
261
|
end
|
213
262
|
|
263
|
+
def self.case?(arg)
|
264
|
+
arg.is_a?(Class) && arg < Case
|
265
|
+
end
|
266
|
+
|
214
267
|
def self.case_or_flow?(arg)
|
215
|
-
|
268
|
+
case?(arg) || arg.is_a?(Cases::Flow)
|
216
269
|
end
|
217
270
|
end
|