u-case 3.0.0.rc7 → 4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0102a68d35e94a3fec4c86a68289412a97d8aa5b9bf960b3dc08cc122b990f80
4
- data.tar.gz: 7183f0447bb6b79315bf9425d3ec77037bc1b7a99384cdf8b3aa3e061cb9ea8b
3
+ metadata.gz: e5a9b11b39c8c90670c4308c91e4e887871eb8f98a1fb739c4be71885a14d0b8
4
+ data.tar.gz: d4ce16229a9afd7dd4d1a1cf8e5b11067a11a6317c6857264ba46b324b220994
5
5
  SHA512:
6
- metadata.gz: 1c9403cbe651b87a63ac73e65c7dc72158a095f1edfd5789ed84e4024418f7b2ca34d99f3319f098459ec22c9211b0d372694fddb9242e53fbdae5cf3f59edd7
7
- data.tar.gz: 65194dbc56bf9f6ae785c6980643b625a8d8c96be63700ea1b10343e5cac3fa317eb4aee4a0d787116a64738dcc26c6b5ed7beeda67de09a006c48868d194b1d
6
+ metadata.gz: '078f264aa7ca294bcbc12e97b4ef210a11a46151adc94d7954846e81f6e6f1647896969ee8fcf40b1bf715145b7adf029f7d22d26f226c7071d29ea477ca56b7'
7
+ data.tar.gz: e5a24e5095cb1178e92919d3f953bfbc6d690242dffafb9b8cdc4ce7c00e943c9921d4013e76b3e062d4269d32b4e4f7bb133951cc0e395416090b36cbf91b36
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
- gem 'simplecov', require: false
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
- ![Ruby](https://img.shields.io/badge/ruby-2.2+-ruby.svg?colorA=99004d&colorB=cc0066)
2
- [![Gem](https://img.shields.io/gem/v/u-case.svg?style=flat-square)](https://rubygems.org/gems/u-case)
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 - Represent use cases in a simple and powerful way while writing modular, expressive and sequentially logical code.">
6
3
 
7
- <img src="./assets/ucase_logo_v1.png" alt="u-case - Create simple and powerful use cases as Ruby objects.">
4
+ <p align="center"><i>Represent use cases in a simple and powerful way while writing modular, expressive and sequentially logical code.</i></p>
5
+ <br>
6
+ </p>
8
7
 
9
- Create simple and powerful use cases as Ruby objects.
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,8 @@ The main project goals are:
21
38
 
22
39
  Version | Documentation
23
40
  --------- | -------------
24
- 3.0.0.rc7 | https://github.com/serradura/u-case/blob/main/README.md
41
+ 4.0.0 | https://github.com/serradura/u-case/blob/main/README.md
42
+ 3.1.0 | https://github.com/serradura/u-case/blob/v3.x/README.md
25
43
  2.6.0 | https://github.com/serradura/u-case/blob/v2.x/README.md
26
44
  1.1.0 | https://github.com/serradura/u-case/blob/v1.x/README.md
27
45
 
@@ -60,15 +78,18 @@ Version | Documentation
60
78
  - [`Kind::Validator`](#kindvalidator)
61
79
  - [`Micro::Case.config`](#microcaseconfig)
62
80
  - [Benchmarks](#benchmarks)
63
- - [`Micro::Case` (v3.0.0)](#microcase-v300)
81
+ - [`Micro::Case`](#microcase)
64
82
  - [Success results](#success-results)
65
83
  - [Failure results](#failure-results)
66
- - [`Micro::Cases::Flow` (v3.0.0)](#microcasesflow-v300)
84
+ - [`Micro::Cases::Flow`](#microcasesflow)
85
+ - [Running the benchmarks](#running-the-benchmarks)
86
+ - [Performance (Benchmarks IPS)](#performance-benchmarks-ips)
87
+ - [Memory profiling](#memory-profiling)
67
88
  - [Comparisons](#comparisons)
68
89
  - [Examples](#examples)
69
- - [1️⃣ Rails App (API)](#1️⃣-rails-app-api)
70
- - [2️⃣ CLI calculator](#2️⃣-cli-calculator)
71
- - [3️⃣ Users creation](#3️⃣-users-creation)
90
+ - [1️⃣ Users creation](#1️⃣-users-creation)
91
+ - [2️⃣ Rails App (API)](#2️⃣-rails-app-api)
92
+ - [3️⃣ CLI calculator](#3️⃣-cli-calculator)
72
93
  - [4️⃣ Rescuing exceptions inside of the use cases](#4️⃣-rescuing-exceptions-inside-of-the-use-cases)
73
94
  - [Development](#development)
74
95
  - [Contributing](#contributing)
@@ -77,11 +98,12 @@ Version | Documentation
77
98
 
78
99
  ## Compatibility
79
100
 
80
- | u-case | branch | ruby | activemodel |
81
- | -------------- | ------- | -------- | ------------- |
82
- | 3.0.0.rc7 | main | >= 2.2.0 | >= 3.2, < 6.1 |
83
- | 2.6.0 | v2.x | >= 2.2.0 | >= 3.2, < 6.1 |
84
- | 1.1.0 | v1.x | >= 2.2.0 | >= 3.2, < 6.1 |
101
+ | u-case | branch | ruby | activemodel | u-attributes |
102
+ | -------------- | ------- | -------- | ------------- | ------------ |
103
+ | 4.0.0 | 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 |
85
107
 
86
108
  > Note: The activemodel is an optional dependency, this module [can be enabled](#u-casewith_activemodel_validation---how-to-validate-use-case-attributes) to validate the use cases' attributes.
87
109
 
@@ -102,7 +124,7 @@ Version | Documentation
102
124
  Add this line to your application's Gemfile:
103
125
 
104
126
  ```ruby
105
- gem 'u-case', '~> 3.0.0.rc7'
127
+ gem 'u-case', '~> 3.1.0'
106
128
  ```
107
129
 
108
130
  And then execute:
@@ -111,7 +133,7 @@ And then execute:
111
133
 
112
134
  Or install it yourself as:
113
135
 
114
- $ gem install u-case --pre
136
+ $ gem install u-case
115
137
 
116
138
  ## Usage
117
139
 
@@ -1060,7 +1082,7 @@ class Multiply < Micro::Case
1060
1082
  validates :a, :b, presence: true, numericality: true
1061
1083
 
1062
1084
  def call!
1063
- return Failure :validation_error, result: { errors: self.errors } if invalid?
1085
+ return Failure :invalid_attributes, result: { errors: self.errors } if invalid?
1064
1086
 
1065
1087
  Success result: { number: a * b }
1066
1088
  end
@@ -1170,109 +1192,110 @@ end
1170
1192
 
1171
1193
  ## Benchmarks
1172
1194
 
1173
- ### `Micro::Case` (v3.0.0)
1195
+ ### `Micro::Case`
1174
1196
 
1175
1197
  #### Success results
1176
1198
 
1177
1199
  | Gem / Abstraction | Iterations per second | Comparison |
1178
1200
  | ----------------- | --------------------: | ----------------: |
1179
- | Dry::Monads | 139037.7 | _**The Fastest**_ |
1180
- | **Micro::Case** | 101497.3 | 1.37x slower |
1181
- | Interactor | 30694.2 | 4.53x slower |
1182
- | Trailblazer::Operation | 14580.8 | 9.54x slower |
1183
- | Dry::Transaction | 5728.0 | 24.27x slower |
1201
+ | Dry::Monads | 281515.4 | _**The Fastest**_ |
1202
+ | **Micro::Case** | 151711.3 | 1.86x slower |
1203
+ | Interactor | 53016.2 | 5.31x slower |
1204
+ | Trailblazer::Operation | 38314.2 | 7.35x slower |
1205
+ | Dry::Transaction | 10440.7 | 26.96x slower |
1184
1206
 
1185
1207
  <details>
1186
1208
  <summary>Show the full <a href="https://github.com/evanphx/benchmark-ips">benchmark/ips</a> results.</summary>
1187
1209
 
1188
1210
  ```ruby
1189
1211
  # Warming up --------------------------------------
1190
- # Interactor 3.056k i/100ms
1191
- # Trailblazer::Operation 1.480k i/100ms
1192
- # Dry::Monads 14.316k i/100ms
1193
- # Dry::Transaction 576.000 i/100ms
1194
- # Micro::Case 10.388k i/100ms
1195
- # Micro::Case::Strict 8.223k i/100ms
1196
- # Micro::Case::Safe 10.057k i/100ms
1212
+ # Interactor 5.151k i/100ms
1213
+ # Trailblazer::Operation 3.805k i/100ms
1214
+ # Dry::Monads 28.153k i/100ms
1215
+ # Dry::Transaction 1.063k i/100ms
1216
+ # Micro::Case 15.159k i/100ms
1217
+ # Micro::Case::Safe 15.172k i/100ms
1218
+ # Micro::Case::Strict 12.557k i/100ms
1197
1219
 
1198
1220
  # Calculating -------------------------------------
1199
- # Interactor 30.694k2.3%) i/s - 155.856k in 5.080475s
1200
- # Trailblazer::Operation 14.581k3.9%) i/s - 74.000k in 5.083091s
1201
- # Dry::Monads 139.038k3.0%) i/s - 701.484k in 5.049921s
1202
- # Dry::Transaction 5.728k3.6%) i/s - 28.800k in 5.034599s
1203
- # Micro::Case 100.712k3.4%) i/s - 509.012k in 5.060139s
1204
- # Micro::Case::Strict 81.513k3.4%) i/s - 411.150k in 5.049962s
1205
- # Micro::Case::Safe 101.497k3.1%) i/s - 512.907k in 5.058463s
1221
+ # Interactor 53.016k1.8%) i/s - 267.852k in 5.053967s
1222
+ # Trailblazer::Operation 38.314k1.7%) i/s - 194.055k in 5.066374s
1223
+ # Dry::Monads 281.515k2.4%) i/s - 1.408M in 5.003266s
1224
+ # Dry::Transaction 10.441k2.1%) i/s - 53.150k in 5.092957s
1225
+ # Micro::Case 151.711k1.7%) i/s - 773.109k in 5.097555s
1226
+ # Micro::Case::Safe 145.801k6.7%) i/s - 728.256k in 5.022666s
1227
+ # Micro::Case::Strict 115.636k8.4%) i/s - 577.622k in 5.042079s
1206
1228
 
1207
1229
  # Comparison:
1208
- # Dry::Monads: 139037.7 i/s
1209
- # Micro::Case::Safe: 101497.3 i/s - 1.37x (± 0.00) slower
1210
- # Micro::Case: 100711.6 i/s - 1.38x (± 0.00) slower
1211
- # Micro::Case::Strict: 81512.9 i/s - 1.71x (± 0.00) slower
1212
- # Interactor: 30694.2 i/s - 4.53x (± 0.00) slower
1213
- # Trailblazer::Operation: 14580.8 i/s - 9.54x (± 0.00) slower
1214
- # Dry::Transaction: 5728.0 i/s - 24.27x (± 0.00) slower
1230
+ # Dry::Monads: 281515.4 i/s
1231
+ # Micro::Case: 151711.3 i/s - 1.86x (± 0.00) slower
1232
+ # Micro::Case::Safe: 145800.8 i/s - 1.93x (± 0.00) slower
1233
+ # Micro::Case::Strict: 115635.8 i/s - 2.43x (± 0.00) slower
1234
+ # Interactor: 53016.2 i/s - 5.31x (± 0.00) slower
1235
+ # Trailblazer::Operation: 38314.2 i/s - 7.35x (± 0.00) slower
1236
+ # Dry::Transaction: 10440.7 i/s - 26.96x (± 0.00) slower
1215
1237
  ```
1216
1238
  </details>
1217
1239
 
1218
- https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_success_result.rb
1240
+ https://github.com/serradura/u-case/blob/main/benchmarks/perfomance/use_case/success_results.rb
1219
1241
 
1220
1242
  #### Failure results
1221
1243
 
1222
1244
  | Gem / Abstraction | Iterations per second | Comparison |
1223
1245
  | ----------------- | --------------------: | ----------------: |
1224
- | **Micro::Case** | 94619.6 | _**The Fastest**_ |
1225
- | Dry::Monads | 70250.6 | 1.35x slower |
1226
- | Trailblazer::Operation | 14786.1 | 6.40x slower |
1227
- | Interactor | 13770.0 | 6.87x slower |
1228
- | Dry::Transaction | 4994.4 | 18.95x slower |
1246
+ | **Micro::Case** | 140794.0 | _**The Fastest**_ |
1247
+ | Dry::Monads | 133865.5 | 0x slower |
1248
+ | Trailblazer::Operation | 39829.9 | 3.53x slower |
1249
+ | Interactor | 23856.0 | 5.90x slower |
1250
+ | Dry::Transaction | 7975.0 | 17.65x slower |
1229
1251
 
1230
1252
  <details>
1231
1253
  <summary>Show the full <a href="https://github.com/evanphx/benchmark-ips">benchmark/ips</a> results.</summary>
1232
1254
 
1233
1255
  ```ruby
1234
1256
  # Warming up --------------------------------------
1235
- # Interactor 1.408k i/100ms
1236
- # Trailblazer::Operation 1.492k i/100ms
1237
- # Dry::Monads 7.224k i/100ms
1238
- # Dry::Transaction 501.000 i/100ms
1239
- # Micro::Case 9.664k i/100ms
1240
- # Micro::Case::Strict 7.823k i/100ms
1241
- # Micro::Case::Safe 9.464k i/100ms
1257
+ # Interactor 2.351k i/100ms
1258
+ # Trailblazer::Operation 3.941k i/100ms
1259
+ # Dry::Monads 13.567k i/100ms
1260
+ # Dry::Transaction 927.000 i/100ms
1261
+ # Micro::Case 14.959k i/100ms
1262
+ # Micro::Case::Safe 14.904k i/100ms
1263
+ # Micro::Case::Strict 12.007k i/100ms
1242
1264
 
1243
1265
  # Calculating -------------------------------------
1244
- # Interactor 13.770k4.3%) i/s - 68.992k in 5.020330s
1245
- # Trailblazer::Operation 14.786k5.3%) i/s - 74.600k in 5.064700s
1246
- # Dry::Monads 70.251k6.7%) i/s - 353.976k in 5.063010s
1247
- # Dry::Transaction 4.994k4.0%) i/s - 25.050k in 5.023997s
1248
- # Micro::Case 94.620k 3.8%) i/s - 473.536k in 5.012483s
1249
- # Micro::Case::Strict 76.059k3.0%) i/s - 383.327k in 5.044482s
1250
- # Micro::Case::Safe 91.719k 5.6%) i/s - 463.736k in 5.072552s
1266
+ # Interactor 23.856k1.7%) i/s - 119.901k in 5.027585s
1267
+ # Trailblazer::Operation 39.830k1.2%) i/s - 200.991k in 5.047032s
1268
+ # Dry::Monads 133.866k2.5%) i/s - 678.350k in 5.070899s
1269
+ # Dry::Transaction 7.975k8.6%) i/s - 39.861k in 5.036260s
1270
+ # Micro::Case 130.534k24.4%) i/s - 583.401k in 5.040907s
1271
+ # Micro::Case::Safe 140.794k8.1%) i/s - 700.488k in 5.020935s
1272
+ # Micro::Case::Strict 102.641k21.3%) i/s - 480.280k in 5.020354s
1251
1273
 
1252
1274
  # Comparison:
1253
- # Micro::Case: 94619.6 i/s
1254
- # Micro::Case::Safe: 91719.4 i/s - same-ish: difference falls within error
1255
- # Micro::Case::Strict: 76058.7 i/s - 1.24x (± 0.00) slower
1256
- # Dry::Monads: 70250.6 i/s - 1.35x (± 0.00) slower
1257
- # Trailblazer::Operation: 14786.1 i/s - 6.40x (± 0.00) slower
1258
- # Interactor: 13770.0 i/s - 6.87x (± 0.00) slower
1259
- # Dry::Transaction: 4994.4 i/s - 18.95x (± 0.00) slower
1275
+ # Micro::Case::Safe: 140794.0 i/s
1276
+ # Dry::Monads: 133865.5 i/s - same-ish: difference falls within error
1277
+ # Micro::Case: 130534.0 i/s - same-ish: difference falls within error
1278
+ # Micro::Case::Strict: 102640.7 i/s - 1.37x (± 0.00) slower
1279
+ # Trailblazer::Operation: 39829.9 i/s - 3.53x (± 0.00) slower
1280
+ # Interactor: 23856.0 i/s - 5.90x (± 0.00) slower
1281
+ # Dry::Transaction: 7975.0 i/s - 17.65x (± 0.00) slower
1260
1282
  ```
1261
1283
  </details>
1262
1284
 
1263
- https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_failure_result.rb
1285
+ https://github.com/serradura/u-case/blob/main/benchmarks/perfomance/use_case/failure_results.rb
1264
1286
 
1265
1287
  ---
1266
1288
 
1267
- ### `Micro::Cases::Flow` (v3.0.0)
1289
+ ### `Micro::Cases::Flow`
1268
1290
 
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) |
1291
+ | Gems / Abstraction | [Success results](https://github.com/serradura/u-case/blob/main/benchmarks/perfomance/flow/success_results.rb) | [Failure results](https://github.com/serradura/u-case/blob/main/benchmarks/perfomance/flow/failure_results.rb) |
1270
1292
  | ------------------------------------------- | ----------------: | ----------------: |
1271
- | Micro::Case internal flow (private methods) | _**The Fastest**_ | _**The Fastest**_ |
1272
- | Micro::Case `then` method | 1.48x slower | 0x slower |
1273
- | Micro::Cases.flow | 1.62x slower | 1.16x slower |
1274
- | Micro::Cases.safe_flow | 1.64x slower | 1.16x slower |
1275
- | Interactor::Organizer | 1.95x slower | 6.17x slower |
1293
+ | Micro::Case::Result `pipe` method | 172734.4 i/s | 153745.6 i/s |
1294
+ | Micro::Case::Result `then` method | 1.24x slower | 1.21x slower |
1295
+ | Micro::Cases.flow | 1.30x slower | 1.30x slower |
1296
+ | Micro::Case class with an inner flow | 2.05x slower | 1.98x slower |
1297
+ | Micro::Case class including itself as a step| 2.14x slower | 2.09x slower |
1298
+ | Interactor::Organizer | 7.69x slower | 7.03x slower |
1276
1299
 
1277
1300
  \* 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
1301
 
@@ -1281,25 +1304,28 @@ https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_failure_r
1281
1304
 
1282
1305
  ```ruby
1283
1306
  # Warming up --------------------------------------
1284
- # Interactor::Organizer 5.219k i/100ms
1285
- # Micro::Cases.flow([]) 6.451k i/100ms
1286
- # Micro::Cases::safe_flow([]) 6.421k i/100ms
1287
- # Micro::Case flow using `then` method 7.139k i/100ms
1288
- # Micro::Case flow using private methods 10.355k i/100ms
1307
+ # Interactor::Organizer 2.163k i/100ms
1308
+ # Micro::Cases.flow([]) 13.158k i/100ms
1309
+ # Micro::Case flow in a class 8.400k i/100ms
1310
+ # Micro::Case including the class 8.008k i/100ms
1311
+ # Micro::Case::Result#| 17.151k i/100ms
1312
+ # Micro::Case::Result#then 14.121k i/100ms
1289
1313
 
1290
1314
  # Calculating -------------------------------------
1291
- # Interactor::Organizer 52.959k (± 1.7%) i/s - 266.169k in 5.027332s
1292
- # Micro::Cases.flow([]) 63.947k (± 1.7%) i/s - 322.550k in 5.045597s
1293
- # Micro::Cases::safe_flow([]) 63.047k3.1%) i/s - 321.050k in 5.097228s
1294
- # Micro::Case flow using `then` method 69.644k4.0%) i/s - 349.811k in 5.031120s
1295
- # Micro::Case flow using private methods 103.297k (± 1.4%) i/s - 517.750k in 5.013254s
1315
+ # Interactor::Organizer 22.467k (± 1.8%) i/s - 112.476k in 5.007787s
1316
+ # Micro::Cases.flow([]) 133.183k (± 1.5%) i/s - 671.058k in 5.039815s
1317
+ # Micro::Case flow in a class 84.083k1.8%) i/s - 428.400k in 5.096623s
1318
+ # Micro::Case including the class 80.574k1.6%) i/s - 408.408k in 5.070029s
1319
+ # Micro::Case::Result#| 172.734k (± 1.1%) i/s - 874.701k in 5.064429s
1320
+ # Micro::Case::Result#then 139.799k (± 1.7%) i/s - 706.050k in 5.052035s
1296
1321
 
1297
1322
  # Comparison:
1298
- # Micro::Case flow using private methods: 103297.4 i/s
1299
- # Micro::Case flow using `then` method: 69644.0 i/s - 1.48x (± 0.00) slower
1300
- # Micro::Cases.flow([]): 63946.7 i/s - 1.62x (± 0.00) slower
1301
- # Micro::Cases::safe_flow([]): 63047.2 i/s - 1.64x (± 0.00) slower
1302
- # Interactor::Organizer: 52958.9 i/s - 1.95x (± 0.00) slower
1323
+ # Micro::Case::Result#|: 172734.4 i/s
1324
+ # Micro::Case::Result#then: 139799.0 i/s - 1.24x (± 0.00) slower
1325
+ # Micro::Cases.flow([]): 133182.9 i/s - 1.30x (± 0.00) slower
1326
+ # Micro::Case flow in a class: 84082.6 i/s - 2.05x (± 0.00) slower
1327
+ # Micro::Case including the class: 80574.3 i/s - 2.14x (± 0.00) slower
1328
+ # Interactor::Organizer: 22467.4 i/s - 7.69x (± 0.00) slower
1303
1329
  ```
1304
1330
  </details>
1305
1331
 
@@ -1308,29 +1334,72 @@ https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_failure_r
1308
1334
 
1309
1335
  ```ruby
1310
1336
  # Warming up --------------------------------------
1311
- # Interactor::Organizer 2.381k i/100ms
1312
- # Micro::Cases.flow([]) 12.003k i/100ms
1313
- # Micro::Cases::safe_flow([]) 12.771k i/100ms
1314
- # Micro::Case flow using `then` method 15.085k i/100ms
1315
- # Micro::Case flow using private methods 14.254k i/100ms
1337
+ # Interactor::Organizer 2.167k i/100ms
1338
+ # Micro::Cases.flow([]) 11.797k i/100ms
1339
+ # Micro::Case flow in a class 7.783k i/100ms
1340
+ # Micro::Case including the class 7.097k i/100ms
1341
+ # Micro::Case::Result#| 14.398k i/100ms
1342
+ # Micro::Case::Result#then 12.719k i/100ms
1316
1343
 
1317
1344
  # Calculating -------------------------------------
1318
- # Interactor::Organizer 23.579k3.2%) i/s - 119.050k in 5.054410s
1319
- # Micro::Cases.flow([]) 124.072k3.4%) i/s - 624.156k in 5.036618s
1320
- # Micro::Cases::safe_flow([]) 124.894k3.6%) i/s - 625.779k in 5.017494s
1321
- # Micro::Case flow using `then` method 145.370k4.8%) i/s - 739.165k in 5.096972s
1322
- # Micro::Case flow using private methods 139.753k (± 5.6%) i/s - 698.446k in 5.015207s
1345
+ # Interactor::Organizer 21.863k2.5%) i/s - 110.517k in 5.058420s
1346
+ # Micro::Cases.flow([]) 118.124k1.8%) i/s - 601.647k in 5.095102s
1347
+ # Micro::Case flow in a class 77.801k1.5%) i/s - 389.150k in 5.003002s
1348
+ # Micro::Case including the class 73.533k2.1%) i/s - 369.044k in 5.021076s
1349
+ # Micro::Case::Result#| 153.746k1.5%) i/s - 777.492k in 5.058177s
1350
+ # Micro::Case::Result#then 126.897k (± 1.7%) i/s - 635.950k in 5.013059s
1323
1351
 
1324
1352
  # Comparison:
1325
- # Micro::Case flow using `then` method: 145369.7 i/s
1326
- # Micro::Case flow using private methods: 139753.4 i/s - same-ish: difference falls within error
1327
- # Micro::Cases::safe_flow([]): 124893.7 i/s - 1.16x (± 0.00) slower
1328
- # Micro::Cases.flow([]): 124071.8 i/s - 1.17x (± 0.00) slower
1329
- # Interactor::Organizer: 23578.7 i/s - 6.17x (± 0.00) slower
1353
+ # Micro::Case::Result#|: 153745.6 i/s
1354
+ # Micro::Case::Result#then: 126896.6 i/s - 1.21x (± 0.00) slower
1355
+ # Micro::Cases.flow([]): 118123.9 i/s - 1.30x (± 0.00) slower
1356
+ # Micro::Case flow in a class: 77800.7 i/s - 1.98x (± 0.00) slower
1357
+ # Micro::Case including the class: 73532.9 i/s - 2.09x (± 0.00) slower
1358
+ # Interactor::Organizer: 21862.9 i/s - 7.03x (± 0.00) slower
1330
1359
  ```
1331
1360
  </details>
1332
1361
 
1333
- https://github.com/serradura/u-case/tree/main/benchmarks/flow
1362
+ https://github.com/serradura/u-case/blob/main/benchmarks/perfomance/flow/
1363
+
1364
+ [⬆️ Back to Top](#table-of-contents-)
1365
+
1366
+ ### Running the benchmarks
1367
+
1368
+ #### Performance (Benchmarks IPS)
1369
+
1370
+ Clone this repo and access its folder, then run the commands below:
1371
+
1372
+ **Use cases**
1373
+
1374
+ ```sh
1375
+ ruby benchmarks/perfomance/use_case/failure_results.rb
1376
+ ruby benchmarks/perfomance/use_case/success_results.rb
1377
+ ```
1378
+
1379
+ **Flows**
1380
+
1381
+ ```sh
1382
+ ruby benchmarks/perfomance/flow/failure_results.rb
1383
+ ruby benchmarks/perfomance/flow/success_results.rb
1384
+ ```
1385
+
1386
+ #### Memory profiling
1387
+
1388
+ **Use cases**
1389
+
1390
+ ```sh
1391
+ ./benchmarks/memory/use_case/success/with_transitions/analyze.sh
1392
+ ./benchmarks/memory/use_case/success/without_transitions/analyze.sh
1393
+ ```
1394
+
1395
+ **Flows**
1396
+
1397
+ ```sh
1398
+ ./benchmarks/memory/flow/success/with_transitions/analyze.sh
1399
+ ./benchmarks/memory/flow/success/without_transitions/analyze.sh
1400
+ ```
1401
+
1402
+ [⬆️ Back to Top](#table-of-contents-)
1334
1403
 
1335
1404
  ### Comparisons
1336
1405
 
@@ -1343,24 +1412,24 @@ Check it out implementations of the same use case with different gems/abstractio
1343
1412
 
1344
1413
  ## Examples
1345
1414
 
1346
- ### 1️⃣ Rails App (API)
1415
+ ### 1️⃣ Users creation
1416
+
1417
+ > 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.
1418
+ >
1419
+ > Link: https://github.com/serradura/u-case/blob/main/examples/users_creation
1420
+
1421
+ ### 2️⃣ Rails App (API)
1347
1422
 
1348
1423
  > 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
1424
  >
1350
1425
  > Link: https://github.com/serradura/from-fat-controllers-to-use-cases
1351
1426
 
1352
- ### 2️⃣ CLI calculator
1427
+ ### 3️⃣ CLI calculator
1353
1428
 
1354
1429
  > Rake tasks to demonstrate how to handle user data, and how to use different failure types to control the program flow.
1355
1430
  >
1356
1431
  > Link: https://github.com/serradura/u-case/tree/main/examples/calculator
1357
1432
 
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
1433
  ### 4️⃣ Rescuing exceptions inside of the use cases
1365
1434
 
1366
1435
  > Link: https://github.com/serradura/u-case/blob/main/examples/rescuing_exceptions.rb