flows 0.3.0 → 0.4.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/.github/workflows/{build.yml → test.yml} +5 -10
- data/.gitignore +1 -0
- data/.reek.yml +42 -0
- data/.rubocop.yml +20 -7
- data/.ruby-version +1 -1
- data/.yardopts +1 -0
- data/CHANGELOG.md +42 -0
- data/Gemfile +0 -6
- data/Gemfile.lock +139 -74
- data/README.md +158 -364
- data/Rakefile +35 -1
- data/bin/.rubocop.yml +5 -0
- data/bin/all_the_errors +47 -0
- data/bin/benchmark +73 -105
- data/bin/benchmark_cli/compare.rb +118 -0
- data/bin/benchmark_cli/compare/a_plus_b.rb +22 -0
- data/bin/benchmark_cli/compare/base.rb +45 -0
- data/bin/benchmark_cli/compare/command.rb +47 -0
- data/bin/benchmark_cli/compare/ten_steps.rb +22 -0
- data/bin/benchmark_cli/examples.rb +23 -0
- data/bin/benchmark_cli/examples/.rubocop.yml +19 -0
- data/bin/benchmark_cli/examples/a_plus_b/dry_do.rb +23 -0
- data/bin/benchmark_cli/examples/a_plus_b/dry_transaction.rb +17 -0
- data/bin/benchmark_cli/examples/a_plus_b/flows_do.rb +22 -0
- data/bin/benchmark_cli/examples/a_plus_b/flows_railway.rb +13 -0
- data/bin/benchmark_cli/examples/a_plus_b/flows_scp.rb +13 -0
- data/bin/benchmark_cli/examples/a_plus_b/flows_scp_mut.rb +13 -0
- data/bin/benchmark_cli/examples/a_plus_b/flows_scp_oc.rb +21 -0
- data/bin/benchmark_cli/examples/a_plus_b/trailblazer.rb +15 -0
- data/bin/benchmark_cli/examples/ten_steps/dry_do.rb +70 -0
- data/bin/benchmark_cli/examples/ten_steps/dry_transaction.rb +64 -0
- data/bin/benchmark_cli/examples/ten_steps/flows_do.rb +69 -0
- data/bin/benchmark_cli/examples/ten_steps/flows_railway.rb +58 -0
- data/bin/benchmark_cli/examples/ten_steps/flows_scp.rb +58 -0
- data/bin/benchmark_cli/examples/ten_steps/flows_scp_mut.rb +58 -0
- data/bin/benchmark_cli/examples/ten_steps/flows_scp_oc.rb +66 -0
- data/bin/benchmark_cli/examples/ten_steps/trailblazer.rb +60 -0
- data/bin/benchmark_cli/helpers.rb +12 -0
- data/bin/benchmark_cli/ruby.rb +15 -0
- data/bin/benchmark_cli/ruby/command.rb +38 -0
- data/bin/benchmark_cli/ruby/method_exec.rb +71 -0
- data/bin/benchmark_cli/ruby/self_class.rb +69 -0
- data/bin/benchmark_cli/ruby/structs.rb +90 -0
- data/bin/console +1 -0
- data/bin/docserver +7 -0
- data/bin/errors +118 -0
- data/bin/errors_cli/contract_error_demo.rb +49 -0
- data/bin/errors_cli/di_error_demo.rb +38 -0
- data/bin/errors_cli/flows_router_error_demo.rb +15 -0
- data/bin/errors_cli/oc_error_demo.rb +40 -0
- data/bin/errors_cli/railway_error_demo.rb +10 -0
- data/bin/errors_cli/result_error_demo.rb +13 -0
- data/bin/errors_cli/scp_error_demo.rb +17 -0
- data/docs/README.md +2 -186
- data/docs/_sidebar.md +0 -24
- data/docs/index.html +1 -1
- data/flows.gemspec +25 -2
- data/forspell.dict +9 -0
- data/lefthook.yml +9 -0
- data/lib/flows.rb +11 -5
- data/lib/flows/contract.rb +402 -0
- data/lib/flows/contract/array.rb +55 -0
- data/lib/flows/contract/case_eq.rb +41 -0
- data/lib/flows/contract/compose.rb +77 -0
- data/lib/flows/contract/either.rb +53 -0
- data/lib/flows/contract/error.rb +25 -0
- data/lib/flows/contract/hash.rb +75 -0
- data/lib/flows/contract/hash_of.rb +70 -0
- data/lib/flows/contract/helpers.rb +22 -0
- data/lib/flows/contract/predicate.rb +34 -0
- data/lib/flows/contract/transformer.rb +50 -0
- data/lib/flows/contract/tuple.rb +70 -0
- data/lib/flows/flow.rb +75 -7
- data/lib/flows/flow/node.rb +131 -0
- data/lib/flows/flow/router.rb +25 -0
- data/lib/flows/flow/router/custom.rb +54 -0
- data/lib/flows/flow/router/errors.rb +11 -0
- data/lib/flows/flow/router/simple.rb +20 -0
- data/lib/flows/plugin.rb +13 -0
- data/lib/flows/plugin/dependency_injector.rb +159 -0
- data/lib/flows/plugin/dependency_injector/dependency.rb +24 -0
- data/lib/flows/plugin/dependency_injector/dependency_definition.rb +16 -0
- data/lib/flows/plugin/dependency_injector/dependency_list.rb +57 -0
- data/lib/flows/plugin/dependency_injector/errors.rb +58 -0
- data/lib/flows/plugin/implicit_init.rb +45 -0
- data/lib/flows/plugin/output_contract.rb +84 -0
- data/lib/flows/plugin/output_contract/dsl.rb +36 -0
- data/lib/flows/plugin/output_contract/errors.rb +74 -0
- data/lib/flows/plugin/output_contract/wrapper.rb +53 -0
- data/lib/flows/railway.rb +140 -37
- data/lib/flows/railway/dsl.rb +8 -19
- data/lib/flows/railway/errors.rb +8 -12
- data/lib/flows/railway/step.rb +24 -0
- data/lib/flows/railway/step_list.rb +38 -0
- data/lib/flows/result.rb +188 -2
- data/lib/flows/result/do.rb +160 -16
- data/lib/flows/result/err.rb +12 -6
- data/lib/flows/result/errors.rb +29 -17
- data/lib/flows/result/helpers.rb +25 -3
- data/lib/flows/result/ok.rb +12 -6
- data/lib/flows/shared_context_pipeline.rb +216 -0
- data/lib/flows/shared_context_pipeline/dsl.rb +63 -0
- data/lib/flows/shared_context_pipeline/errors.rb +17 -0
- data/lib/flows/shared_context_pipeline/mutation_step.rb +31 -0
- data/lib/flows/shared_context_pipeline/router_definition.rb +21 -0
- data/lib/flows/shared_context_pipeline/step.rb +46 -0
- data/lib/flows/shared_context_pipeline/track.rb +67 -0
- data/lib/flows/shared_context_pipeline/track_list.rb +46 -0
- data/lib/flows/util.rb +17 -0
- data/lib/flows/util/inheritable_singleton_vars.rb +79 -0
- data/lib/flows/util/inheritable_singleton_vars/dup_strategy.rb +109 -0
- data/lib/flows/util/inheritable_singleton_vars/isolation_strategy.rb +104 -0
- data/lib/flows/util/prepend_to_class.rb +145 -0
- data/lib/flows/version.rb +1 -1
- metadata +233 -37
- data/bin/demo +0 -66
- data/bin/examples.rb +0 -195
- data/bin/profile_10steps +0 -106
- data/bin/ruby_benchmarks +0 -26
- data/docs/CNAME +0 -1
- data/docs/contributing/benchmarks_profiling.md +0 -3
- data/docs/contributing/local_development.md +0 -3
- data/docs/flow/direct_usage.md +0 -3
- data/docs/flow/general_idea.md +0 -3
- data/docs/operation/basic_usage.md +0 -1
- data/docs/operation/inject_steps.md +0 -3
- data/docs/operation/lambda_steps.md +0 -3
- data/docs/operation/result_shapes.md +0 -3
- data/docs/operation/routing_tracks.md +0 -3
- data/docs/operation/wrapping_steps.md +0 -3
- data/docs/overview/performance.md +0 -336
- data/docs/railway/basic_usage.md +0 -232
- data/docs/result_objects/basic_usage.md +0 -196
- data/docs/result_objects/do_notation.md +0 -139
- data/lib/flows/implicit_build.rb +0 -16
- data/lib/flows/node.rb +0 -27
- data/lib/flows/operation.rb +0 -55
- data/lib/flows/operation/builder.rb +0 -130
- data/lib/flows/operation/builder/build_router.rb +0 -37
- data/lib/flows/operation/dsl.rb +0 -93
- data/lib/flows/operation/errors.rb +0 -75
- data/lib/flows/operation/executor.rb +0 -78
- data/lib/flows/railway/builder.rb +0 -68
- data/lib/flows/railway/executor.rb +0 -23
- data/lib/flows/result_router.rb +0 -14
- data/lib/flows/router.rb +0 -22
@@ -0,0 +1,47 @@
|
|
1
|
+
class BenchmarkCLI
|
2
|
+
module Compare
|
3
|
+
# Comparison benchmarks command.
|
4
|
+
class Command
|
5
|
+
include Helpers
|
6
|
+
include Flows::Result::Helpers
|
7
|
+
extend Flows::Result::Do
|
8
|
+
|
9
|
+
def initialize(benchmarks, implementations)
|
10
|
+
@benchmarks = benchmarks.map(&:to_sym)
|
11
|
+
@implementations = implementations.map(&:to_sym)
|
12
|
+
end
|
13
|
+
|
14
|
+
do_notation(:call)
|
15
|
+
def call
|
16
|
+
yield validate_benchmarks
|
17
|
+
yield validate_implementations
|
18
|
+
|
19
|
+
run
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def validate_benchmarks
|
25
|
+
@benchmarks.each do |benchmark|
|
26
|
+
return err_data("Unexpected benchmark: #{benchmark}") unless BENCHMARKS.key?(benchmark)
|
27
|
+
end
|
28
|
+
|
29
|
+
ok
|
30
|
+
end
|
31
|
+
|
32
|
+
def validate_implementations
|
33
|
+
@implementations.each do |impl|
|
34
|
+
return err_data("Unexpected implementation: #{impl}") unless IMPLEMENTATIONS.key?(impl)
|
35
|
+
end
|
36
|
+
|
37
|
+
ok
|
38
|
+
end
|
39
|
+
|
40
|
+
def run
|
41
|
+
@benchmarks.each do |name|
|
42
|
+
BENCHMARKS[name].new(@implementations).call
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class BenchmarkCLI
|
2
|
+
module Compare
|
3
|
+
# '10 steps' comparison.
|
4
|
+
class TenSteps < Base
|
5
|
+
TITLE = '10 steps, each returns `true` or `{ step_name: true }`, no input'.freeze
|
6
|
+
NAME = :ten_steps
|
7
|
+
|
8
|
+
def report_class_call(benchmark, title, klass)
|
9
|
+
benchmark.report title do
|
10
|
+
klass.call
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def report_instance_call(benchmark, title, klass)
|
15
|
+
instance = klass.new
|
16
|
+
benchmark.report title do
|
17
|
+
instance.call
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative 'examples/a_plus_b/dry_do'
|
2
|
+
require_relative 'examples/ten_steps/dry_do'
|
3
|
+
|
4
|
+
require_relative 'examples/a_plus_b/dry_transaction'
|
5
|
+
require_relative 'examples/ten_steps/dry_transaction'
|
6
|
+
|
7
|
+
require_relative 'examples/a_plus_b/flows_do'
|
8
|
+
require_relative 'examples/ten_steps/flows_do'
|
9
|
+
|
10
|
+
require_relative 'examples/a_plus_b/flows_railway'
|
11
|
+
require_relative 'examples/ten_steps/flows_railway'
|
12
|
+
|
13
|
+
require_relative 'examples/a_plus_b/flows_scp'
|
14
|
+
require_relative 'examples/ten_steps/flows_scp'
|
15
|
+
|
16
|
+
require_relative 'examples/a_plus_b/flows_scp_oc'
|
17
|
+
require_relative 'examples/ten_steps/flows_scp_oc'
|
18
|
+
|
19
|
+
require_relative 'examples/a_plus_b/flows_scp_mut'
|
20
|
+
require_relative 'examples/ten_steps/flows_scp_mut'
|
21
|
+
|
22
|
+
require_relative 'examples/a_plus_b/trailblazer'
|
23
|
+
require_relative 'examples/ten_steps/trailblazer'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
inherit_from:
|
2
|
+
- ../../.rubocop.yml
|
3
|
+
|
4
|
+
# Examples can contain inaccurate or meaningless code
|
5
|
+
|
6
|
+
Naming/MethodParameterName:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Lint/UnusedMethodArgument:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
Style/Documentation:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
Lint/UselessAssignment:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Metrics/MethodLength:
|
19
|
+
Enabled: false
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'dry/monads'
|
2
|
+
require 'dry/monads/do'
|
3
|
+
|
4
|
+
class BenchmarkCLI
|
5
|
+
module Examples
|
6
|
+
module APlusB
|
7
|
+
class DryDo
|
8
|
+
include Dry::Monads[:result]
|
9
|
+
|
10
|
+
include Dry::Monads::Do.for(:call)
|
11
|
+
def call(a:, b:)
|
12
|
+
Success(yield do_call(a, b))
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def do_call(a, b)
|
18
|
+
Success(a + b)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class BenchmarkCLI
|
2
|
+
module Examples
|
3
|
+
module APlusB
|
4
|
+
class FlowsDo
|
5
|
+
include Flows::Result::Helpers
|
6
|
+
|
7
|
+
extend Flows::Result::Do
|
8
|
+
|
9
|
+
do_notation(:call)
|
10
|
+
def call(a:, b:)
|
11
|
+
ok_data(yield do_call(a, b))
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def do_call(a, b)
|
17
|
+
ok_data(a + b)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class BenchmarkCLI
|
2
|
+
module Examples
|
3
|
+
module APlusB
|
4
|
+
class FlowsSCPOC < Flows::SharedContextPipeline
|
5
|
+
include Flows::Plugin::OutputContract
|
6
|
+
|
7
|
+
step :calculation
|
8
|
+
|
9
|
+
success_with :ok do
|
10
|
+
hash_of(
|
11
|
+
sum: Integer
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
def calculation(a:, b:)
|
16
|
+
ok(sum: a + b)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'dry/monads'
|
2
|
+
require 'dry/monads/do'
|
3
|
+
|
4
|
+
class BenchmarkCLI
|
5
|
+
module Examples
|
6
|
+
module TenSteps
|
7
|
+
class DryDo
|
8
|
+
include Dry::Monads[:result]
|
9
|
+
|
10
|
+
include Dry::Monads::Do.for(:call)
|
11
|
+
def call
|
12
|
+
x1 = yield s1(:s1)
|
13
|
+
x2 = yield s2(:s2)
|
14
|
+
x3 = yield s3(:s3)
|
15
|
+
x4 = yield s4(:s4)
|
16
|
+
x5 = yield s5(:s5)
|
17
|
+
x6 = yield s6(:s6)
|
18
|
+
x7 = yield s7(:s7)
|
19
|
+
x8 = yield s8(:s8)
|
20
|
+
x9 = yield s9(:s9)
|
21
|
+
x10 = yield s10(:s10)
|
22
|
+
|
23
|
+
Success(x10)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def s1(_x)
|
29
|
+
Success(true)
|
30
|
+
end
|
31
|
+
|
32
|
+
def s2(_x)
|
33
|
+
Success(true)
|
34
|
+
end
|
35
|
+
|
36
|
+
def s3(_x)
|
37
|
+
Success(true)
|
38
|
+
end
|
39
|
+
|
40
|
+
def s4(_x)
|
41
|
+
Success(true)
|
42
|
+
end
|
43
|
+
|
44
|
+
def s5(_x)
|
45
|
+
Success(true)
|
46
|
+
end
|
47
|
+
|
48
|
+
def s6(_x)
|
49
|
+
Success(true)
|
50
|
+
end
|
51
|
+
|
52
|
+
def s7(_x)
|
53
|
+
Success(true)
|
54
|
+
end
|
55
|
+
|
56
|
+
def s8(_x)
|
57
|
+
Success(true)
|
58
|
+
end
|
59
|
+
|
60
|
+
def s9(_x)
|
61
|
+
Success(true)
|
62
|
+
end
|
63
|
+
|
64
|
+
def s10(_x)
|
65
|
+
Success(true)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'dry/transaction'
|
2
|
+
|
3
|
+
class BenchmarkCLI
|
4
|
+
module Examples
|
5
|
+
module TenSteps
|
6
|
+
class DryTransaction
|
7
|
+
include Dry::Transaction
|
8
|
+
|
9
|
+
step :s1
|
10
|
+
step :s2
|
11
|
+
step :s3
|
12
|
+
step :s4
|
13
|
+
step :s5
|
14
|
+
step :s6
|
15
|
+
step :s7
|
16
|
+
step :s8
|
17
|
+
step :s9
|
18
|
+
step :s10
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def s1(_x)
|
23
|
+
Success(true)
|
24
|
+
end
|
25
|
+
|
26
|
+
def s2(_x)
|
27
|
+
Success(true)
|
28
|
+
end
|
29
|
+
|
30
|
+
def s3(_x)
|
31
|
+
Success(true)
|
32
|
+
end
|
33
|
+
|
34
|
+
def s4(_x)
|
35
|
+
Success(true)
|
36
|
+
end
|
37
|
+
|
38
|
+
def s5(_x)
|
39
|
+
Success(true)
|
40
|
+
end
|
41
|
+
|
42
|
+
def s6(_x)
|
43
|
+
Success(true)
|
44
|
+
end
|
45
|
+
|
46
|
+
def s7(_x)
|
47
|
+
Success(true)
|
48
|
+
end
|
49
|
+
|
50
|
+
def s8(_x)
|
51
|
+
Success(true)
|
52
|
+
end
|
53
|
+
|
54
|
+
def s9(_x)
|
55
|
+
Success(true)
|
56
|
+
end
|
57
|
+
|
58
|
+
def s10(_x)
|
59
|
+
Success(true)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
class BenchmarkCLI
|
2
|
+
module Examples
|
3
|
+
module TenSteps
|
4
|
+
class FlowsDo
|
5
|
+
include Flows::Result::Helpers
|
6
|
+
|
7
|
+
extend Flows::Result::Do
|
8
|
+
|
9
|
+
do_notation(:call)
|
10
|
+
def call
|
11
|
+
x1 = yield s1(:s1)
|
12
|
+
x2 = yield s2(:s2)
|
13
|
+
x3 = yield s3(:s3)
|
14
|
+
x4 = yield s4(:s4)
|
15
|
+
x5 = yield s5(:s5)
|
16
|
+
x6 = yield s6(:s6)
|
17
|
+
x7 = yield s7(:s7)
|
18
|
+
x8 = yield s8(:s8)
|
19
|
+
x9 = yield s9(:s9)
|
20
|
+
x10 = yield s10(:s10)
|
21
|
+
|
22
|
+
ok
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def s1(_sym)
|
28
|
+
ok_data(true)
|
29
|
+
end
|
30
|
+
|
31
|
+
def s2(_sym)
|
32
|
+
ok_data(true)
|
33
|
+
end
|
34
|
+
|
35
|
+
def s3(_sym)
|
36
|
+
ok_data(true)
|
37
|
+
end
|
38
|
+
|
39
|
+
def s4(_sym)
|
40
|
+
ok_data(true)
|
41
|
+
end
|
42
|
+
|
43
|
+
def s5(_sym)
|
44
|
+
ok_data(true)
|
45
|
+
end
|
46
|
+
|
47
|
+
def s6(_sym)
|
48
|
+
ok_data(true)
|
49
|
+
end
|
50
|
+
|
51
|
+
def s7(_sym)
|
52
|
+
ok_data(true)
|
53
|
+
end
|
54
|
+
|
55
|
+
def s8(_sym)
|
56
|
+
ok_data(true)
|
57
|
+
end
|
58
|
+
|
59
|
+
def s9(_sym)
|
60
|
+
ok_data(true)
|
61
|
+
end
|
62
|
+
|
63
|
+
def s10(_sym)
|
64
|
+
ok_data(true)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|