u-case 3.0.0.rc5 → 3.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/README.md +142 -112
- data/README.pt-BR.md +144 -114
- data/lib/micro/case.rb +13 -19
- data/lib/micro/case/config.rb +16 -4
- data/lib/micro/case/error.rb +3 -1
- data/lib/micro/case/result.rb +60 -32
- data/lib/micro/case/safe.rb +1 -1
- data/lib/micro/case/version.rb +1 -1
- data/lib/micro/case/with_activemodel_validation.rb +3 -1
- data/lib/micro/cases/flow.rb +12 -20
- data/lib/micro/cases/safe/flow.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fe9a88c0c01e52d2f89ba28578c4b67c8cd1d6e303a49ff1ce2d11e5e543159
|
4
|
+
data.tar.gz: a105e4f13e760d03e201a6d6246a0b39e96e0452465953ca0d1767e93d927711
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfed6efdf05b4960bb63c43926cfb2aa6a35b394f665c9a1e472f2ebf05568d418bd04e4c075bea2c990e896131ba57281455ab9fc153d4d4ee4196773798ff4
|
7
|
+
data.tar.gz: 6573ad028e83794fa6851f15a27e3b96a1368d84345e1a8aede633c6f1962bde2ff20e0222bdad9c833dabbe22e90a190ea1c092ef8cab4258d443c9bf91f652
|
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
@@ -1,6 +1,6 @@
|
|
1
1
|

|
2
2
|
[](https://rubygems.org/gems/u-case)
|
3
|
-
[](https://travis-ci.com/serradura/u-case)
|
4
4
|
[](https://codeclimate.com/github/serradura/u-case/maintainability)
|
5
5
|
[](https://codeclimate.com/github/serradura/u-case/test_coverage)
|
6
6
|
|
@@ -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 | 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 | 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'
|
106
106
|
```
|
107
107
|
|
108
108
|
And then execute:
|
@@ -1060,7 +1060,7 @@ class Multiply < Micro::Case
|
|
1060
1060
|
validates :a, :b, presence: true, numericality: true
|
1061
1061
|
|
1062
1062
|
def call!
|
1063
|
-
return Failure :
|
1063
|
+
return Failure :invalid_attributes, result: { errors: self.errors } if invalid?
|
1064
1064
|
|
1065
1065
|
Success result: { number: a * b }
|
1066
1066
|
end
|
@@ -1176,103 +1176,104 @@ 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
|
|
1218
|
-
https://github.com/serradura/u-case/blob/
|
1218
|
+
https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_success_result.rb
|
1219
1219
|
|
1220
1220
|
#### Failure results
|
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
|
|
1263
|
-
https://github.com/serradura/u-case/blob/
|
1263
|
+
https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_failure_result.rb
|
1264
1264
|
|
1265
1265
|
---
|
1266
1266
|
|
1267
1267
|
### `Micro::Cases::Flow` (v3.0.0)
|
1268
1268
|
|
1269
|
-
| Gems / Abstraction | [Success results](https://github.com/serradura/u-case/blob/
|
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/master/benchmarks/use_case/with_failure
|
|
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,62 +1324,76 @@ https://github.com/serradura/u-case/blob/master/benchmarks/use_case/with_failure
|
|
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
|
|
1333
|
-
https://github.com/serradura/u-case/tree/
|
1363
|
+
https://github.com/serradura/u-case/tree/main/benchmarks/flow
|
1334
1364
|
|
1335
1365
|
### Comparisons
|
1336
1366
|
|
1337
1367
|
Check it out implementations of the same use case with different gems/abstractions.
|
1338
1368
|
|
1339
|
-
* [interactor](https://github.com/serradura/u-case/blob/
|
1340
|
-
* [u-case](https://github.com/serradura/u-case/blob/
|
1369
|
+
* [interactor](https://github.com/serradura/u-case/blob/main/comparisons/interactor.rb)
|
1370
|
+
* [u-case](https://github.com/serradura/u-case/blob/main/comparisons/u-case.rb)
|
1341
1371
|
|
1342
1372
|
[⬆️ Back to Top](#table-of-contents-)
|
1343
1373
|
|
1344
1374
|
## Examples
|
1345
1375
|
|
1346
|
-
### 1️⃣
|
1376
|
+
### 1️⃣ Users creation
|
1347
1377
|
|
1348
|
-
>
|
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.
|
1349
1379
|
>
|
1350
|
-
> Link: https://github.com/serradura/
|
1380
|
+
> Link: https://github.com/serradura/u-case/blob/main/examples/users_creation
|
1351
1381
|
|
1352
|
-
### 2️⃣
|
1382
|
+
### 2️⃣ Rails App (API)
|
1353
1383
|
|
1354
|
-
>
|
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.
|
1355
1385
|
>
|
1356
|
-
> Link: https://github.com/serradura/
|
1386
|
+
> Link: https://github.com/serradura/from-fat-controllers-to-use-cases
|
1357
1387
|
|
1358
|
-
### 3️⃣
|
1388
|
+
### 3️⃣ CLI calculator
|
1359
1389
|
|
1360
|
-
>
|
1390
|
+
> Rake tasks to demonstrate how to handle user data, and how to use different failure types to control the program flow.
|
1361
1391
|
>
|
1362
|
-
> Link: https://github.com/serradura/u-case/
|
1392
|
+
> Link: https://github.com/serradura/u-case/tree/main/examples/calculator
|
1363
1393
|
|
1364
1394
|
### 4️⃣ Rescuing exceptions inside of the use cases
|
1365
1395
|
|
1366
|
-
> Link: https://github.com/serradura/u-case/blob/
|
1396
|
+
> Link: https://github.com/serradura/u-case/blob/main/examples/rescuing_exceptions.rb
|
1367
1397
|
|
1368
1398
|
[⬆️ Back to Top](#table-of-contents-)
|
1369
1399
|
|
@@ -1383,4 +1413,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
1383
1413
|
|
1384
1414
|
## Code of Conduct
|
1385
1415
|
|
1386
|
-
Everyone interacting in the Micro::Case project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/serradura/u-case/blob/
|
1416
|
+
Everyone interacting in the Micro::Case project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/serradura/u-case/blob/main/CODE_OF_CONDUCT.md).
|
data/README.pt-BR.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|

|
2
2
|
[](https://rubygems.org/gems/u-case)
|
3
|
-
[](https://travis-ci.com/serradura/u-case)
|
4
4
|
[](https://codeclimate.com/github/serradura/u-case/maintainability)
|
5
5
|
[](https://codeclimate.com/github/serradura/u-case/test_coverage)
|
6
6
|
|
@@ -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 | 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
|
|
@@ -34,7 +34,7 @@ Versão | Documentação
|
|
34
34
|
- [`Micro::Case::Result` - O que é o resultado de um caso de uso?](#microcaseresult---o-que-é-o-resultado-de-um-caso-de-uso)
|
35
35
|
- [O que são os tipos de resultados?](#o-que-são-os-tipos-de-resultados)
|
36
36
|
- [Como difinir tipos customizados de resultados?](#como-difinir-tipos-customizados-de-resultados)
|
37
|
-
- [É
|
37
|
+
- [É possível definir um tipo sem definir os dados do resultado?](#é-possível-definir-um-tipo-sem-definir-os-dados-do-resultado)
|
38
38
|
- [Como utilizar os hooks dos resultados?](#como-utilizar-os-hooks-dos-resultados)
|
39
39
|
- [Por que o hook sem um tipo definido expõe o próprio resultado?](#por-que-o-hook-sem-um-tipo-definido-expõe-o-próprio-resultado)
|
40
40
|
- [Usando decomposição para acessar os dados e tipo do resultado](#usando-decomposição-para-acessar-os-dados-e-tipo-do-resultado)
|
@@ -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 | 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'
|
105
105
|
```
|
106
106
|
|
107
107
|
E então execute:
|
@@ -276,7 +276,7 @@ bad_result.failure? # true
|
|
276
276
|
|
277
277
|
[⬆️ Voltar para o índice](#índice-)
|
278
278
|
|
279
|
-
#### É
|
279
|
+
#### É possível definir um tipo sem definir os dados do resultado?
|
280
280
|
|
281
281
|
Resposta: Sim, é possível. Mas isso terá um comportamento especial por conta dos dados do resultado ser um hash com o tipo definido como chave e `true` como o valor.
|
282
282
|
|
@@ -1064,7 +1064,7 @@ class Multiply < Micro::Case
|
|
1064
1064
|
validates :a, :b, presence: true, numericality: true
|
1065
1065
|
|
1066
1066
|
def call!
|
1067
|
-
return Failure :
|
1067
|
+
return Failure :invalid_attributes, result: { errors: self.errors } if invalid?
|
1068
1068
|
|
1069
1069
|
Success result: { number: a * b }
|
1070
1070
|
end
|
@@ -1180,103 +1180,104 @@ 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
|
|
1222
|
-
https://github.com/serradura/u-case/blob/
|
1222
|
+
https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_success_result.rb
|
1223
1223
|
|
1224
1224
|
#### Failure results
|
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
|
|
1267
|
-
https://github.com/serradura/u-case/blob/
|
1267
|
+
https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_failure_result.rb
|
1268
1268
|
|
1269
1269
|
---
|
1270
1270
|
|
1271
1271
|
### `Micro::Cases::Flow` (v3.0.0)
|
1272
1272
|
|
1273
|
-
| Gem / Abstração | [Resultados de sucesso](https://github.com/serradura/u-case/blob/
|
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/master/benchmarks/use_case/with_failure
|
|
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,62 +1328,76 @@ https://github.com/serradura/u-case/blob/master/benchmarks/use_case/with_failure
|
|
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
|
|
1337
|
-
https://github.com/serradura/u-case/tree/
|
1367
|
+
https://github.com/serradura/u-case/tree/main/benchmarks/flow
|
1338
1368
|
|
1339
1369
|
### Comparações
|
1340
1370
|
|
1341
1371
|
Confira as implementações do mesmo caso de uso com diferentes gems/abstrações.
|
1342
1372
|
|
1343
|
-
* [interactor](https://github.com/serradura/u-case/blob/
|
1344
|
-
* [u-case](https://github.com/serradura/u-case/blob/
|
1373
|
+
* [interactor](https://github.com/serradura/u-case/blob/main/comparisons/interactor.rb)
|
1374
|
+
* [u-case](https://github.com/serradura/u-case/blob/main/comparisons/u-case.rb)
|
1345
1375
|
|
1346
1376
|
[⬆️ Voltar para o índice](#índice-)
|
1347
1377
|
|
1348
1378
|
## Exemplos
|
1349
1379
|
|
1350
|
-
### 1️⃣
|
1380
|
+
### 1️⃣ Criação de usuários
|
1351
1381
|
|
1352
|
-
>
|
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`.
|
1353
1383
|
>
|
1354
|
-
> Link: https://github.com/serradura/
|
1384
|
+
> Link: https://github.com/serradura/u-case/blob/main/examples/users_creation
|
1355
1385
|
|
1356
|
-
### 2️⃣
|
1386
|
+
### 2️⃣ Rails App (API)
|
1357
1387
|
|
1358
|
-
>
|
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.
|
1359
1389
|
>
|
1360
|
-
> Link: https://github.com/serradura/
|
1390
|
+
> Link: https://github.com/serradura/from-fat-controllers-to-use-cases
|
1361
1391
|
|
1362
|
-
### 3️⃣
|
1392
|
+
### 3️⃣ CLI calculator
|
1363
1393
|
|
1364
|
-
>
|
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.
|
1365
1395
|
>
|
1366
|
-
> Link: https://github.com/serradura/u-case/
|
1396
|
+
> Link: https://github.com/serradura/u-case/tree/main/examples/calculator
|
1367
1397
|
|
1368
1398
|
### 4️⃣ Interceptando exceções dentro dos casos de uso
|
1369
1399
|
|
1370
|
-
> Link: https://github.com/serradura/u-case/blob/
|
1400
|
+
> Link: https://github.com/serradura/u-case/blob/main/examples/rescuing_exceptions.rb
|
1371
1401
|
|
1372
1402
|
[⬆️ Voltar para o índice](#índice-)
|
1373
1403
|
|
@@ -1387,4 +1417,4 @@ A gem está disponível como código aberto nos termos da [licença MIT](https:/
|
|
1387
1417
|
|
1388
1418
|
## Código de conduta
|
1389
1419
|
|
1390
|
-
Espera-se que todos que interagem com o codebase do projeto `Micro::Case`, issue trackers, chat rooms and mailing lists sigam o [código de conduta](https://github.com/serradura/u-case/blob/
|
1420
|
+
Espera-se que todos que interagem com o codebase do projeto `Micro::Case`, issue trackers, chat rooms and mailing lists sigam o [código de conduta](https://github.com/serradura/u-case/blob/main/CODE_OF_CONDUCT.md).
|