u-case 3.1.0 → 4.2.1

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.
@@ -1,7 +1,7 @@
1
1
  <p align="center">
2
- <img src="./assets/ucase_logo_v1.png" alt="u-case - Create simple and powerful use cases as Ruby objects.">
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>Crie simples e poderosos casos de uso como objetos em Ruby.</i></p>
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
- 3.1.0 | https://github.com/serradura/u-case/blob/main/README.md
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
- | 3.1.0 | main | >= 2.2.0 | >= 3.2, < 6.1 |
99
- | 2.6.0 | v2.x | >= 2.2.0 | >= 3.2, < 6.1 |
100
- | 1.1.0 | v1.x | >= 2.2.0 | >= 3.2, < 6.1 |
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', '~> 3.1.0'
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 --pre
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 | Comparação |
1199
- | ----------------- | --------------------: | ----------------: |
1200
- | Dry::Monads | 141730.1 | _**O mais rápido**_ |
1201
- | **Micro::Case** | 103541.3 | 1.37x slower |
1202
- | Interactor | 29100.8 | 4.87x slower |
1203
- | Trailblazer::Operation | 15031.4 | 9.43x slower |
1204
- | Dry::Transaction | 5674.0 | 24.98x slower |
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 2.915k i/100ms
1212
- # Trailblazer::Operation 1.543k i/100ms
1213
- # Dry::Monads 14.288k i/100ms
1214
- # Dry::Transaction 571.000 i/100ms
1215
- # Micro::Case 10.418k i/100ms
1216
- # Micro::Case::Strict 8.296k i/100ms
1217
- # Micro::Case::Safe 10.254k i/100ms
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 29.101k 2.1%) i/s - 145.750k in 5.010660s
1221
- # Trailblazer::Operation 15.031k (± 2.0%) i/s - 75.607k in 5.032071s
1222
- # Dry::Monads 141.730k 3.1%) i/s - 714.400k in 5.045546s
1223
- # Dry::Transaction 5.674k (± 1.9%) i/s - 28.550k in 5.033564s
1224
- # Micro::Case 103.541k1.6%) i/s - 520.900k in 5.032077s
1225
- # Micro::Case::Strict 83.045k2.4%) i/s - 423.096k in 5.098031s
1226
- # Micro::Case::Safe 101.662k 1.5%) i/s - 512.700k in 5.044386s
1227
+ # Interactor 59.746k29.9%) i/s - 274.128k in 5.049901s
1228
+ # Trailblazer::Operation
1229
+ # 28.424k15.8%) i/s - 141.546k in 5.087882s
1230
+ # Dry::Monads 315.635k6.1%) i/s - 1.588M in 5.048914s
1231
+ # Dry::Transaction 10.131k6.4%) i/s - 50.694k in 5.025150s
1232
+ # Micro::Case 75.838k9.7%) i/s - 379.728k in 5.052573s
1233
+ # Micro::Case::Safe 75.461k10.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: 141730.1 i/s
1230
- # Micro::Case: 103541.3 i/s - 1.37x (± 0.00) slower
1231
- # Micro::Case::Safe: 101662.2 i/s - 1.39x (± 0.00) slower
1232
- # Micro::Case::Strict: 83044.6 i/s - 1.71x (± 0.00) slower
1233
- # Interactor: 29100.8 i/s - 4.87x (± 0.00) slower
1234
- # Trailblazer::Operation: 15031.4 i/s - 9.43x (± 0.00) slower
1235
- # Dry::Transaction: 5674.0 i/s - 24.98x (± 0.00) slower
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/with_success_result.rb
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 | Comparação |
1244
- | ----------------- | --------------------: | ----------------: |
1245
- | **Micro::Case** | 98820.8 | _**O mais rápido**_ |
1246
- | Dry::Monads | 71329.7 | 1.39x slower |
1247
- | Trailblazer::Operation | 15034.9 | 6.57x slower |
1248
- | Interactor | 13958.7 | 7.08x slower |
1249
- | Dry::Transaction | 5067.5 | 19.50x slower |
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 1.324k i/100ms
1257
- # Trailblazer::Operation 1.525k i/100ms
1258
- # Dry::Monads 7.126k i/100ms
1259
- # Dry::Transaction 499.000 i/100ms
1260
- # Micro::Case 9.919k i/100ms
1261
- # Micro::Case::Strict 7.837k i/100ms
1262
- # Micro::Case::Safe 9.762k i/100ms
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 13.959k 2.5%) i/s - 70.172k in 5.030240s
1266
- # Trailblazer::Operation 15.035k 2.2%) i/s - 76.250k in 5.074108s
1267
- # Dry::Monads 71.330k 2.4%) i/s - 363.426k in 5.097993s
1268
- # Dry::Transaction 5.068k1.9%) i/s - 25.449k in 5.023922s
1269
- # Micro::Case 98.821k2.9%) i/s - 495.950k in 5.023421s
1270
- # Micro::Case::Strict 79.936k3.1%) i/s - 399.687k in 5.005435s
1271
- # Micro::Case::Safe 98.695k1.9%) i/s - 497.862k in 5.046246s
1273
+ # Interactor 27.037k24.9%) i/s - 128.674k in 5.102133s
1274
+ # Trailblazer::Operation 29.016k12.4%) i/s - 145.266k in 5.074991s
1275
+ # Dry::Monads 135.387k15.1%) i/s - 669.300k in 5.055356s
1276
+ # Dry::Transaction 8.989k9.2%) i/s - 45.136k in 5.084820s
1277
+ # Micro::Case 73.247k9.9%) i/s - 364.944k in 5.030449s
1278
+ # Micro::Case::Safe 73.489k9.6%) i/s - 364.704k in 5.007282s
1279
+ # Micro::Case::Strict 61.980k8.0%) i/s - 308.900k in 5.014821s
1272
1280
 
1273
1281
  # Comparison:
1274
- # Micro::Case: 98820.8 i/s
1275
- # Micro::Case::Safe: 98695.0 i/s - same-ish: difference falls within error
1276
- # Micro::Case::Strict: 79935.9 i/s - 1.24x (± 0.00) slower
1277
- # Dry::Monads: 71329.7 i/s - 1.39x (± 0.00) slower
1278
- # Trailblazer::Operation: 15034.9 i/s - 6.57x (± 0.00) slower
1279
- # Interactor: 13958.7 i/s - 7.08x (± 0.00) slower
1280
- # Dry::Transaction: 5067.5 i/s - 19.50x (± 0.00) slower
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/with_failure_result.rb
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/with_success_result.rb#L40) | [Resultados de falha](https://github.com/serradura/u-case/blob/main/benchmarks/flow/with_failure_result.rb#L40) |
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 internal flow (private methods) | _**O mais rápido**_ | _**O mais rápido**_ |
1293
- | Micro::Case internal flow (through lambdas) | 1.03x slower | 1.04x slower |
1294
- | Micro::Case `then` method | 1.49x slower | 0x slower |
1295
- | Micro::Cases.flow | 1.53x slower | 1.04x slower |
1296
- | Micro::Cases.safe_flow | 1.54x slower | 1.04x slower |
1297
- | Interactor::Organizer | 2.05x slower | 6.27x slower |
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
- # 4.837k i/100ms
1308
- # Micro::Cases.flow([])
1309
- # 6.755k i/100ms
1310
- # Micro::Cases::safe_flow([])
1311
- # 6.809k i/100ms
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
- # 50.731k 1.6%) i/s - 256.361k in 5.054694s
1322
- # Micro::Cases.flow([])
1323
- # 67.757k1.6%) i/s - 344.505k in 5.085681s
1324
- # Micro::Cases::safe_flow([])
1325
- # 67.613k1.6%) i/s - 340.450k in 5.036562s
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.790k11.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.030k8.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.459k8.8%) i/s - 356.900k in 5.030526s
1332
1328
 
1333
1329
  # Comparison:
1334
- # Micro::Case flow using private methods: 103787.5 i/s
1335
- # Micro::Case flow using private methods through lambdas: 101080.6 i/s - 1.03x (± 0.00) slower
1336
- # Micro::Case flow using `then` method: 69483.3 i/s - 1.49x (± 0.00) slower
1337
- # Micro::Cases.flow([]): 67757.2 i/s - 1.53x (± 0.00) slower
1338
- # Micro::Cases::safe_flow([]): 67613.3 i/s - 1.54x (± 0.00) slower
1339
- # Interactor::Organizer: 50730.8 i/s - 2.05x (± 0.00) slower
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
- # 2.299k i/100ms
1350
- # Micro::Cases.flow([])
1351
- # 14.187k i/100ms
1352
- # Micro::Cases::safe_flow([])
1353
- # 13.609k i/100ms
1354
- # Micro::Case flow using `then` method
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
- # 23.306k2.1%) i/s - 117.249k in 5.033171s
1363
- # Micro::Cases.flow([])
1364
- # 140.111k1.6%) i/s - 709.350k in 5.064041s
1365
- # Micro::Cases::safe_flow([])
1366
- # 139.927k1.7%) i/s - 707.668k in 5.058971s
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.999k9.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.921k8.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.898k8.8%) i/s - 347.412k in 5.080116s
1373
1358
 
1374
1359
  # Comparison:
1375
- # Micro::Case flow using `then` method: 146073.0 i/s
1376
- # Micro::Case flow using private methods: 142091.7 i/s - same-ish: difference falls within error
1377
- # Micro::Case flow using private methods through lambdas: 140791.1 i/s - 1.04x (± 0.00) slower
1378
- # Micro::Cases.flow([]): 140110.8 i/s - 1.04x (± 0.00) slower
1379
- # Micro::Cases::safe_flow([]): 139926.6 i/s - 1.04x (± 0.00) slower
1380
- # Interactor::Organizer: 23305.9 i/s - 6.27x (± 0.00) slower
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/tree/main/benchmarks/flow
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
 
@@ -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.without(:strict_initialize)
20
+ include Micro::Attributes
20
21
 
21
- def self.call(options = Kind::Empty::HASH)
22
- new(options).__call__
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.attributes(self.attributes_data({}))
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
- call
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 call
152
- return __call_use_case_flow if __call_use_case_flow?
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 __call_use_case_flow?
212
+ def __call_the_use_case_flow?
174
213
  self.class.__flow_get__
175
214
  end
176
215
 
177
- def __call_use_case_flow
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 __result
204
- @__result ||= Result.new
242
+ def __get_result(is_success, value, type)
243
+ @__result.__set__(is_success, value, type, self)
205
244
  end
206
245
 
207
- def __get_result(is_success, value, type)
208
- __result.__set__(is_success, value, type, self)
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
- (arg.is_a?(Class) && arg < Case) || arg.is_a?(Cases::Flow)
268
+ case?(arg) || arg.is_a?(Cases::Flow)
216
269
  end
217
270
  end