u-case 3.0.0.rc6 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.sh +8 -4
- data/Gemfile +9 -1
- data/README.md +160 -113
- data/README.pt-BR.md +181 -134
- data/lib/micro/case.rb +20 -15
- data/lib/micro/case/config.rb +16 -4
- data/lib/micro/case/error.rb +3 -1
- data/lib/micro/case/result.rb +54 -49
- data/lib/micro/case/result/transitions.rb +20 -0
- data/lib/micro/case/safe.rb +2 -2
- data/lib/micro/case/utils.rb +1 -0
- data/lib/micro/case/version.rb +1 -1
- data/lib/micro/case/with_activemodel_validation.rb +3 -1
- data/lib/micro/cases/flow.rb +18 -14
- data/lib/micro/cases/safe/flow.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3472991bd5b3d6198cb7455044ac8144445b61c860ce76ca191eba1f6e09aac
|
4
|
+
data.tar.gz: eebefecaa4a27d98f3a558aa17a1731de6639a69cc5011fc6acdf430a7e1f52b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8cc6cc9994b30bc71b3a5485123dcd41a5583c195bba9969da41e85efb6ebb964f4ee5e39d02f86e324a2cbea24b420f1a9fa67d1dca410c8a60539873d80b9
|
7
|
+
data.tar.gz: 48b7f05a0473dba7885d1907d794b503c44030de29b53e0fd757f71597e37c8d0248db980b071ae8f2492e207bfddb0616b25dd9acbefd219318114f72b73339
|
data/.travis.sh
CHANGED
@@ -3,17 +3,21 @@
|
|
3
3
|
ruby_v=$(ruby -v)
|
4
4
|
|
5
5
|
ACTIVEMODEL_VERSION='3.2' bundle update
|
6
|
-
ACTIVEMODEL_VERSION='3.2' bundle exec rake test
|
6
|
+
ACTIVEMODEL_VERSION='3.2' ENABLE_TRANSITIONS='false' bundle exec rake test
|
7
|
+
ACTIVEMODEL_VERSION='3.2' ENABLE_TRANSITIONS='true' bundle exec rake test
|
7
8
|
|
8
9
|
if [[ ! $ruby_v =~ '2.2.0' ]]; then
|
9
10
|
ACTIVEMODEL_VERSION='5.2' bundle update
|
10
|
-
ACTIVEMODEL_VERSION='5.2' bundle exec rake test
|
11
|
+
ACTIVEMODEL_VERSION='5.2' ENABLE_TRANSITIONS='false' bundle exec rake test
|
12
|
+
ACTIVEMODEL_VERSION='5.2' ENABLE_TRANSITIONS='true' bundle exec rake test
|
11
13
|
fi
|
12
14
|
|
13
15
|
if [[ $ruby_v =~ '2.5.' ]] || [[ $ruby_v =~ '2.6.' ]] || [[ $ruby_v =~ '2.7.' ]]; then
|
14
16
|
ACTIVEMODEL_VERSION='6.0' bundle update
|
15
|
-
ACTIVEMODEL_VERSION='6.0' bundle exec rake test
|
17
|
+
ACTIVEMODEL_VERSION='6.0' ENABLE_TRANSITIONS='false' bundle exec rake test
|
18
|
+
ACTIVEMODEL_VERSION='6.0' ENABLE_TRANSITIONS='true' bundle exec rake test
|
16
19
|
fi
|
17
20
|
|
18
21
|
bundle update
|
19
|
-
bundle exec rake test
|
22
|
+
ENABLE_TRANSITIONS='false' bundle exec rake test
|
23
|
+
ENABLE_TRANSITIONS='true' bundle exec rake test
|
data/Gemfile
CHANGED
@@ -15,9 +15,17 @@ if activemodel_version < '6.1.0'
|
|
15
15
|
gem 'activesupport', activemodel, require: false
|
16
16
|
end
|
17
17
|
|
18
|
+
simplecov_version =
|
19
|
+
case RUBY_VERSION
|
20
|
+
when /\A2.[23]/ then '~> 0.17.1'
|
21
|
+
when /\A2.4/ then '~> 0.18.5'
|
22
|
+
else '~> 0.19'
|
23
|
+
end
|
24
|
+
|
18
25
|
group :test do
|
19
26
|
gem 'minitest', activemodel_version < '4.1' ? '~> 4.2' : '~> 5.0'
|
20
|
-
|
27
|
+
|
28
|
+
gem 'simplecov', simplecov_version, require: false
|
21
29
|
end
|
22
30
|
|
23
31
|
pry_byebug_version =
|
data/README.md
CHANGED
@@ -1,12 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
[![Build Status](https://travis-ci.com/serradura/u-case.svg?branch=main)](https://travis-ci.com/serradura/u-case)
|
4
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/5c3c8ad1b0b943f88efd/maintainability)](https://codeclimate.com/github/serradura/u-case/maintainability)
|
5
|
-
[![Test Coverage](https://api.codeclimate.com/v1/badges/5c3c8ad1b0b943f88efd/test_coverage)](https://codeclimate.com/github/serradura/u-case/test_coverage)
|
1
|
+
<p align="center">
|
2
|
+
<img src="./assets/ucase_logo_v1.png" alt="u-case - Create simple and powerful use cases as Ruby objects.">
|
6
3
|
|
7
|
-
<
|
4
|
+
<p align="center"><i>Create simple and powerful use cases as Ruby objects.</i></p>
|
5
|
+
<br>
|
6
|
+
</p>
|
8
7
|
|
9
|
-
|
8
|
+
<p align="center">
|
9
|
+
<img src="https://img.shields.io/badge/ruby-2.2+-ruby.svg?colorA=99004d&colorB=cc0066" alt="Ruby">
|
10
|
+
|
11
|
+
<a href="https://rubygems.org/gems/u-case">
|
12
|
+
<img alt="Gem" src="https://img.shields.io/gem/v/u-case.svg?style=flat-square">
|
13
|
+
</a>
|
14
|
+
|
15
|
+
<a href="https://travis-ci.com/serradura/u-case">
|
16
|
+
<img alt="Build Status" src="https://travis-ci.com/serradura/u-case.svg?branch=main">
|
17
|
+
</a>
|
18
|
+
|
19
|
+
<a href="https://codeclimate.com/github/serradura/u-case/maintainability">
|
20
|
+
<img alt="Maintainability" src="https://api.codeclimate.com/v1/badges/5c3c8ad1b0b943f88efd/maintainability">
|
21
|
+
</a>
|
22
|
+
|
23
|
+
<a href="https://codeclimate.com/github/serradura/u-case/test_coverage">
|
24
|
+
<img alt="Test Coverage" src="https://api.codeclimate.com/v1/badges/5c3c8ad1b0b943f88efd/test_coverage">
|
25
|
+
</a>
|
26
|
+
</p>
|
10
27
|
|
11
28
|
The main project goals are:
|
12
29
|
1. Easy to use and easy to learn (input **>>** process **>>** output).
|
@@ -21,7 +38,7 @@ The main project goals are:
|
|
21
38
|
|
22
39
|
Version | Documentation
|
23
40
|
--------- | -------------
|
24
|
-
3.
|
41
|
+
3.1.0 | https://github.com/serradura/u-case/blob/main/README.md
|
25
42
|
2.6.0 | https://github.com/serradura/u-case/blob/v2.x/README.md
|
26
43
|
1.1.0 | https://github.com/serradura/u-case/blob/v1.x/README.md
|
27
44
|
|
@@ -60,15 +77,15 @@ Version | Documentation
|
|
60
77
|
- [`Kind::Validator`](#kindvalidator)
|
61
78
|
- [`Micro::Case.config`](#microcaseconfig)
|
62
79
|
- [Benchmarks](#benchmarks)
|
63
|
-
- [`Micro::Case`
|
80
|
+
- [`Micro::Case`](#microcase)
|
64
81
|
- [Success results](#success-results)
|
65
82
|
- [Failure results](#failure-results)
|
66
|
-
- [`Micro::Cases::Flow`
|
83
|
+
- [`Micro::Cases::Flow`](#microcasesflow)
|
67
84
|
- [Comparisons](#comparisons)
|
68
85
|
- [Examples](#examples)
|
69
|
-
- [1️⃣
|
70
|
-
- [2️⃣
|
71
|
-
- [3️⃣
|
86
|
+
- [1️⃣ Users creation](#1️⃣-users-creation)
|
87
|
+
- [2️⃣ Rails App (API)](#2️⃣-rails-app-api)
|
88
|
+
- [3️⃣ CLI calculator](#3️⃣-cli-calculator)
|
72
89
|
- [4️⃣ Rescuing exceptions inside of the use cases](#4️⃣-rescuing-exceptions-inside-of-the-use-cases)
|
73
90
|
- [Development](#development)
|
74
91
|
- [Contributing](#contributing)
|
@@ -79,7 +96,7 @@ Version | Documentation
|
|
79
96
|
|
80
97
|
| u-case | branch | ruby | activemodel |
|
81
98
|
| -------------- | ------- | -------- | ------------- |
|
82
|
-
| 3.
|
99
|
+
| 3.1.0 | main | >= 2.2.0 | >= 3.2, < 6.1 |
|
83
100
|
| 2.6.0 | v2.x | >= 2.2.0 | >= 3.2, < 6.1 |
|
84
101
|
| 1.1.0 | v1.x | >= 2.2.0 | >= 3.2, < 6.1 |
|
85
102
|
|
@@ -102,7 +119,7 @@ Version | Documentation
|
|
102
119
|
Add this line to your application's Gemfile:
|
103
120
|
|
104
121
|
```ruby
|
105
|
-
gem 'u-case', '~> 3.
|
122
|
+
gem 'u-case', '~> 3.1.0'
|
106
123
|
```
|
107
124
|
|
108
125
|
And then execute:
|
@@ -1060,7 +1077,7 @@ class Multiply < Micro::Case
|
|
1060
1077
|
validates :a, :b, presence: true, numericality: true
|
1061
1078
|
|
1062
1079
|
def call!
|
1063
|
-
return Failure :
|
1080
|
+
return Failure :invalid_attributes, result: { errors: self.errors } if invalid?
|
1064
1081
|
|
1065
1082
|
Success result: { number: a * b }
|
1066
1083
|
end
|
@@ -1170,48 +1187,48 @@ end
|
|
1170
1187
|
|
1171
1188
|
## Benchmarks
|
1172
1189
|
|
1173
|
-
### `Micro::Case`
|
1190
|
+
### `Micro::Case`
|
1174
1191
|
|
1175
1192
|
#### Success results
|
1176
1193
|
|
1177
1194
|
| Gem / Abstraction | Iterations per second | Comparison |
|
1178
1195
|
| ----------------- | --------------------: | ----------------: |
|
1179
|
-
| Dry::Monads |
|
1180
|
-
| **Micro::Case** |
|
1181
|
-
| Interactor |
|
1182
|
-
| Trailblazer::Operation |
|
1183
|
-
| Dry::Transaction |
|
1196
|
+
| Dry::Monads | 141730.1 | _**The Fastest**_ |
|
1197
|
+
| **Micro::Case** | 103541.3 | 1.37x slower |
|
1198
|
+
| Interactor | 29100.8 | 4.87x slower |
|
1199
|
+
| Trailblazer::Operation | 15031.4 | 9.43x slower |
|
1200
|
+
| Dry::Transaction | 5674.0 | 24.98x slower |
|
1184
1201
|
|
1185
1202
|
<details>
|
1186
1203
|
<summary>Show the full <a href="https://github.com/evanphx/benchmark-ips">benchmark/ips</a> results.</summary>
|
1187
1204
|
|
1188
1205
|
```ruby
|
1189
1206
|
# 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.
|
1207
|
+
# Interactor 2.915k i/100ms
|
1208
|
+
# Trailblazer::Operation 1.543k i/100ms
|
1209
|
+
# Dry::Monads 14.288k i/100ms
|
1210
|
+
# Dry::Transaction 571.000 i/100ms
|
1211
|
+
# Micro::Case 10.418k i/100ms
|
1212
|
+
# Micro::Case::Strict 8.296k i/100ms
|
1213
|
+
# Micro::Case::Safe 10.254k i/100ms
|
1197
1214
|
|
1198
1215
|
# 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.
|
1216
|
+
# Interactor 29.101k (± 2.1%) i/s - 145.750k in 5.010660s
|
1217
|
+
# Trailblazer::Operation 15.031k (± 2.0%) i/s - 75.607k in 5.032071s
|
1218
|
+
# Dry::Monads 141.730k (± 3.1%) i/s - 714.400k in 5.045546s
|
1219
|
+
# Dry::Transaction 5.674k (± 1.9%) i/s - 28.550k in 5.033564s
|
1220
|
+
# Micro::Case 103.541k (± 1.6%) i/s - 520.900k in 5.032077s
|
1221
|
+
# Micro::Case::Strict 83.045k (± 2.4%) i/s - 423.096k in 5.098031s
|
1222
|
+
# Micro::Case::Safe 101.662k (± 1.5%) i/s - 512.700k in 5.044386s
|
1206
1223
|
|
1207
1224
|
# Comparison:
|
1208
|
-
# Dry::Monads:
|
1209
|
-
#
|
1210
|
-
#
|
1211
|
-
# Micro::Case::Strict:
|
1212
|
-
# Interactor:
|
1213
|
-
# Trailblazer::Operation:
|
1214
|
-
# Dry::Transaction:
|
1225
|
+
# Dry::Monads: 141730.1 i/s
|
1226
|
+
# Micro::Case: 103541.3 i/s - 1.37x (± 0.00) slower
|
1227
|
+
# Micro::Case::Safe: 101662.2 i/s - 1.39x (± 0.00) slower
|
1228
|
+
# Micro::Case::Strict: 83044.6 i/s - 1.71x (± 0.00) slower
|
1229
|
+
# Interactor: 29100.8 i/s - 4.87x (± 0.00) slower
|
1230
|
+
# Trailblazer::Operation: 15031.4 i/s - 9.43x (± 0.00) slower
|
1231
|
+
# Dry::Transaction: 5674.0 i/s - 24.98x (± 0.00) slower
|
1215
1232
|
```
|
1216
1233
|
</details>
|
1217
1234
|
|
@@ -1221,42 +1238,42 @@ https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_success_r
|
|
1221
1238
|
|
1222
1239
|
| Gem / Abstraction | Iterations per second | Comparison |
|
1223
1240
|
| ----------------- | --------------------: | ----------------: |
|
1224
|
-
| **Micro::Case** |
|
1225
|
-
| Dry::Monads |
|
1226
|
-
| Trailblazer::Operation |
|
1227
|
-
| Interactor |
|
1228
|
-
| Dry::Transaction |
|
1241
|
+
| **Micro::Case** | 98820.8 | _**The Fastest**_ |
|
1242
|
+
| Dry::Monads | 71329.7 | 1.39x slower |
|
1243
|
+
| Trailblazer::Operation | 15034.9 | 6.57x slower |
|
1244
|
+
| Interactor | 13958.7 | 7.08x slower |
|
1245
|
+
| Dry::Transaction | 5067.5 | 19.50x slower |
|
1229
1246
|
|
1230
1247
|
<details>
|
1231
1248
|
<summary>Show the full <a href="https://github.com/evanphx/benchmark-ips">benchmark/ips</a> results.</summary>
|
1232
1249
|
|
1233
1250
|
```ruby
|
1234
1251
|
# 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.
|
1252
|
+
# Interactor 1.324k i/100ms
|
1253
|
+
# Trailblazer::Operation 1.525k i/100ms
|
1254
|
+
# Dry::Monads 7.126k i/100ms
|
1255
|
+
# Dry::Transaction 499.000 i/100ms
|
1256
|
+
# Micro::Case 9.919k i/100ms
|
1257
|
+
# Micro::Case::Strict 7.837k i/100ms
|
1258
|
+
# Micro::Case::Safe 9.762k i/100ms
|
1242
1259
|
|
1243
1260
|
# Calculating -------------------------------------
|
1244
|
-
# Interactor 13.
|
1245
|
-
# Trailblazer::Operation
|
1246
|
-
# Dry::Monads
|
1247
|
-
# Dry::Transaction
|
1248
|
-
# Micro::Case
|
1249
|
-
# Micro::Case::Strict
|
1250
|
-
# Micro::Case::Safe
|
1261
|
+
# Interactor 13.959k (± 2.5%) i/s - 70.172k in 5.030240s
|
1262
|
+
# Trailblazer::Operation 15.035k (± 2.2%) i/s - 76.250k in 5.074108s
|
1263
|
+
# Dry::Monads 71.330k (± 2.4%) i/s - 363.426k in 5.097993s
|
1264
|
+
# Dry::Transaction 5.068k (± 1.9%) i/s - 25.449k in 5.023922s
|
1265
|
+
# Micro::Case 98.821k (± 2.9%) i/s - 495.950k in 5.023421s
|
1266
|
+
# Micro::Case::Strict 79.936k (± 3.1%) i/s - 399.687k in 5.005435s
|
1267
|
+
# Micro::Case::Safe 98.695k (± 1.9%) i/s - 497.862k in 5.046246s
|
1251
1268
|
|
1252
1269
|
# Comparison:
|
1253
|
-
# Micro::Case:
|
1254
|
-
# Micro::Case::Safe:
|
1255
|
-
# Micro::Case::Strict:
|
1256
|
-
# Dry::Monads:
|
1257
|
-
# Trailblazer::Operation:
|
1258
|
-
# Interactor:
|
1259
|
-
# Dry::Transaction:
|
1270
|
+
# Micro::Case: 98820.8 i/s
|
1271
|
+
# Micro::Case::Safe: 98695.0 i/s - same-ish: difference falls within error
|
1272
|
+
# Micro::Case::Strict: 79935.9 i/s - 1.24x (± 0.00) slower
|
1273
|
+
# Dry::Monads: 71329.7 i/s - 1.39x (± 0.00) slower
|
1274
|
+
# Trailblazer::Operation: 15034.9 i/s - 6.57x (± 0.00) slower
|
1275
|
+
# Interactor: 13958.7 i/s - 7.08x (± 0.00) slower
|
1276
|
+
# Dry::Transaction: 5067.5 i/s - 19.50x (± 0.00) slower
|
1260
1277
|
```
|
1261
1278
|
</details>
|
1262
1279
|
|
@@ -1264,15 +1281,16 @@ https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_failure_r
|
|
1264
1281
|
|
1265
1282
|
---
|
1266
1283
|
|
1267
|
-
### `Micro::Cases::Flow`
|
1284
|
+
### `Micro::Cases::Flow`
|
1268
1285
|
|
1269
1286
|
| 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
1287
|
| ------------------------------------------- | ----------------: | ----------------: |
|
1271
1288
|
| Micro::Case internal flow (private methods) | _**The Fastest**_ | _**The Fastest**_ |
|
1272
|
-
| Micro::Case
|
1273
|
-
| Micro::
|
1274
|
-
| Micro::Cases.
|
1275
|
-
|
|
1289
|
+
| Micro::Case internal flow (through lambdas) | 1.03x slower | 1.04x slower |
|
1290
|
+
| Micro::Case `then` method | 1.49x slower | 0x slower |
|
1291
|
+
| Micro::Cases.flow | 1.53x slower | 1.04x slower |
|
1292
|
+
| Micro::Cases.safe_flow | 1.54x slower | 1.04x slower |
|
1293
|
+
| Interactor::Organizer | 2.05x slower | 6.27x slower |
|
1276
1294
|
|
1277
1295
|
\* 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
1296
|
|
@@ -1281,25 +1299,40 @@ https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_failure_r
|
|
1281
1299
|
|
1282
1300
|
```ruby
|
1283
1301
|
# Warming up --------------------------------------
|
1284
|
-
# Interactor::Organizer
|
1285
|
-
#
|
1286
|
-
# Micro::Cases
|
1287
|
-
#
|
1288
|
-
# Micro::
|
1302
|
+
# Interactor::Organizer
|
1303
|
+
# 4.837k i/100ms
|
1304
|
+
# Micro::Cases.flow([])
|
1305
|
+
# 6.755k i/100ms
|
1306
|
+
# Micro::Cases::safe_flow([])
|
1307
|
+
# 6.809k i/100ms
|
1308
|
+
# Micro::Case flow using `then` method
|
1309
|
+
# 6.968k i/100ms
|
1310
|
+
# Micro::Case flow using private methods
|
1311
|
+
# 10.362k i/100ms
|
1312
|
+
# Micro::Case flow using private methods through lambdas
|
1313
|
+
# 10.258k i/100ms
|
1289
1314
|
|
1290
1315
|
# Calculating -------------------------------------
|
1291
|
-
# Interactor::Organizer
|
1292
|
-
#
|
1293
|
-
# Micro::Cases
|
1294
|
-
#
|
1295
|
-
# Micro::
|
1316
|
+
# Interactor::Organizer
|
1317
|
+
# 50.731k (± 1.6%) i/s - 256.361k in 5.054694s
|
1318
|
+
# Micro::Cases.flow([])
|
1319
|
+
# 67.757k (± 1.6%) i/s - 344.505k in 5.085681s
|
1320
|
+
# Micro::Cases::safe_flow([])
|
1321
|
+
# 67.613k (± 1.6%) i/s - 340.450k in 5.036562s
|
1322
|
+
# Micro::Case flow using `then` method
|
1323
|
+
# 69.483k (± 1.5%) i/s - 348.400k in 5.015351s
|
1324
|
+
# Micro::Case flow using private methods
|
1325
|
+
# 103.788k (± 1.0%) i/s - 528.462k in 5.092240s
|
1326
|
+
# Micro::Case flow using private methods through lambdas
|
1327
|
+
# 101.081k (± 1.2%) i/s - 512.900k in 5.074904s
|
1296
1328
|
|
1297
1329
|
# Comparison:
|
1298
|
-
# Micro::Case flow using private methods:
|
1299
|
-
# Micro::Case flow using
|
1300
|
-
# Micro::
|
1301
|
-
# Micro::Cases
|
1302
|
-
#
|
1330
|
+
# Micro::Case flow using private methods: 103787.5 i/s
|
1331
|
+
# Micro::Case flow using private methods through lambdas: 101080.6 i/s - 1.03x (± 0.00) slower
|
1332
|
+
# Micro::Case flow using `then` method: 69483.3 i/s - 1.49x (± 0.00) slower
|
1333
|
+
# Micro::Cases.flow([]): 67757.2 i/s - 1.53x (± 0.00) slower
|
1334
|
+
# Micro::Cases::safe_flow([]): 67613.3 i/s - 1.54x (± 0.00) slower
|
1335
|
+
# Interactor::Organizer: 50730.8 i/s - 2.05x (± 0.00) slower
|
1303
1336
|
```
|
1304
1337
|
</details>
|
1305
1338
|
|
@@ -1308,25 +1341,39 @@ https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_failure_r
|
|
1308
1341
|
|
1309
1342
|
```ruby
|
1310
1343
|
# Warming up --------------------------------------
|
1311
|
-
# Interactor::Organizer
|
1312
|
-
#
|
1313
|
-
# Micro::Cases
|
1314
|
-
#
|
1315
|
-
# Micro::
|
1316
|
-
|
1344
|
+
# Interactor::Organizer
|
1345
|
+
# 2.299k i/100ms
|
1346
|
+
# Micro::Cases.flow([])
|
1347
|
+
# 14.187k i/100ms
|
1348
|
+
# Micro::Cases::safe_flow([])
|
1349
|
+
# 13.609k i/100ms
|
1350
|
+
# Micro::Case flow using `then` method
|
1351
|
+
# 14.578k i/100ms
|
1352
|
+
# Micro::Case flow using private methods
|
1353
|
+
# 14.101k i/100ms
|
1354
|
+
# Micro::Case flow using private methods through lambdas
|
1355
|
+
# 13.670k i/100ms
|
1317
1356
|
# Calculating -------------------------------------
|
1318
|
-
# Interactor::Organizer
|
1319
|
-
#
|
1320
|
-
# Micro::Cases
|
1321
|
-
#
|
1322
|
-
# Micro::
|
1357
|
+
# Interactor::Organizer
|
1358
|
+
# 23.306k (± 2.1%) i/s - 117.249k in 5.033171s
|
1359
|
+
# Micro::Cases.flow([])
|
1360
|
+
# 140.111k (± 1.6%) i/s - 709.350k in 5.064041s
|
1361
|
+
# Micro::Cases::safe_flow([])
|
1362
|
+
# 139.927k (± 1.7%) i/s - 707.668k in 5.058971s
|
1363
|
+
# Micro::Case flow using `then` method
|
1364
|
+
# 146.073k (± 2.0%) i/s - 743.478k in 5.091741s
|
1365
|
+
# Micro::Case flow using private methods
|
1366
|
+
# 142.092k (± 1.5%) i/s - 719.151k in 5.062298s
|
1367
|
+
# Micro::Case flow using private methods through lambdas
|
1368
|
+
# 140.791k (± 1.2%) i/s - 710.840k in 5.049584s
|
1323
1369
|
|
1324
1370
|
# Comparison:
|
1325
|
-
# Micro::Case flow using `then` method:
|
1326
|
-
# Micro::Case flow using private methods:
|
1327
|
-
# Micro::
|
1328
|
-
# Micro::Cases.flow([]):
|
1329
|
-
#
|
1371
|
+
# Micro::Case flow using `then` method: 146073.0 i/s
|
1372
|
+
# Micro::Case flow using private methods: 142091.7 i/s - same-ish: difference falls within error
|
1373
|
+
# Micro::Case flow using private methods through lambdas: 140791.1 i/s - 1.04x (± 0.00) slower
|
1374
|
+
# Micro::Cases.flow([]): 140110.8 i/s - 1.04x (± 0.00) slower
|
1375
|
+
# Micro::Cases::safe_flow([]): 139926.6 i/s - 1.04x (± 0.00) slower
|
1376
|
+
# Interactor::Organizer: 23305.9 i/s - 6.27x (± 0.00) slower
|
1330
1377
|
```
|
1331
1378
|
</details>
|
1332
1379
|
|
@@ -1343,24 +1390,24 @@ Check it out implementations of the same use case with different gems/abstractio
|
|
1343
1390
|
|
1344
1391
|
## Examples
|
1345
1392
|
|
1346
|
-
### 1️⃣
|
1393
|
+
### 1️⃣ Users creation
|
1394
|
+
|
1395
|
+
> 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.
|
1396
|
+
>
|
1397
|
+
> Link: https://github.com/serradura/u-case/blob/main/examples/users_creation
|
1398
|
+
|
1399
|
+
### 2️⃣ Rails App (API)
|
1347
1400
|
|
1348
1401
|
> 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
1402
|
>
|
1350
1403
|
> Link: https://github.com/serradura/from-fat-controllers-to-use-cases
|
1351
1404
|
|
1352
|
-
###
|
1405
|
+
### 3️⃣ CLI calculator
|
1353
1406
|
|
1354
1407
|
> Rake tasks to demonstrate how to handle user data, and how to use different failure types to control the program flow.
|
1355
1408
|
>
|
1356
1409
|
> Link: https://github.com/serradura/u-case/tree/main/examples/calculator
|
1357
1410
|
|
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
1411
|
### 4️⃣ Rescuing exceptions inside of the use cases
|
1365
1412
|
|
1366
1413
|
> Link: https://github.com/serradura/u-case/blob/main/examples/rescuing_exceptions.rb
|