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,58 @@
|
|
1
|
+
class BenchmarkCLI
|
2
|
+
module Examples
|
3
|
+
module TenSteps
|
4
|
+
class FlowsRailway < Flows::Railway
|
5
|
+
step :s1
|
6
|
+
step :s2
|
7
|
+
step :s3
|
8
|
+
step :s4
|
9
|
+
step :s5
|
10
|
+
step :s6
|
11
|
+
step :s7
|
12
|
+
step :s8
|
13
|
+
step :s9
|
14
|
+
step :s10
|
15
|
+
|
16
|
+
def s1(**)
|
17
|
+
ok(s1: true)
|
18
|
+
end
|
19
|
+
|
20
|
+
def s2(s1:)
|
21
|
+
ok(s2: true)
|
22
|
+
end
|
23
|
+
|
24
|
+
def s3(s2:)
|
25
|
+
ok(s3: true)
|
26
|
+
end
|
27
|
+
|
28
|
+
def s4(s3:)
|
29
|
+
ok(s4: true)
|
30
|
+
end
|
31
|
+
|
32
|
+
def s5(s4:)
|
33
|
+
ok(s5: true)
|
34
|
+
end
|
35
|
+
|
36
|
+
def s6(s5:)
|
37
|
+
ok(s6: true)
|
38
|
+
end
|
39
|
+
|
40
|
+
def s7(s6:)
|
41
|
+
ok(s7: true)
|
42
|
+
end
|
43
|
+
|
44
|
+
def s8(s7:)
|
45
|
+
ok(s8: true)
|
46
|
+
end
|
47
|
+
|
48
|
+
def s9(s8:)
|
49
|
+
ok(s9: true)
|
50
|
+
end
|
51
|
+
|
52
|
+
def s10(s9:)
|
53
|
+
ok(s10: true)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class BenchmarkCLI
|
2
|
+
module Examples
|
3
|
+
module TenSteps
|
4
|
+
class FlowsSCP < Flows::SharedContextPipeline
|
5
|
+
step :s1
|
6
|
+
step :s2
|
7
|
+
step :s3
|
8
|
+
step :s4
|
9
|
+
step :s5
|
10
|
+
step :s6
|
11
|
+
step :s7
|
12
|
+
step :s8
|
13
|
+
step :s9
|
14
|
+
step :s10
|
15
|
+
|
16
|
+
def s1(**)
|
17
|
+
ok(s1: true)
|
18
|
+
end
|
19
|
+
|
20
|
+
def s2(s1:, **)
|
21
|
+
ok(s2: true)
|
22
|
+
end
|
23
|
+
|
24
|
+
def s3(s2:, **)
|
25
|
+
ok(s3: true)
|
26
|
+
end
|
27
|
+
|
28
|
+
def s4(s3:, **)
|
29
|
+
ok(s4: true)
|
30
|
+
end
|
31
|
+
|
32
|
+
def s5(s4:, **)
|
33
|
+
ok(s5: true)
|
34
|
+
end
|
35
|
+
|
36
|
+
def s6(s5:, **)
|
37
|
+
ok(s6: true)
|
38
|
+
end
|
39
|
+
|
40
|
+
def s7(s6:, **)
|
41
|
+
ok(s7: true)
|
42
|
+
end
|
43
|
+
|
44
|
+
def s8(s7:, **)
|
45
|
+
ok(s8: true)
|
46
|
+
end
|
47
|
+
|
48
|
+
def s9(s8:, **)
|
49
|
+
ok(s9: true)
|
50
|
+
end
|
51
|
+
|
52
|
+
def s10(s9:, **)
|
53
|
+
ok(s10: true)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class BenchmarkCLI
|
2
|
+
module Examples
|
3
|
+
module TenSteps
|
4
|
+
class FlowsSCPMut < Flows::SharedContextPipeline
|
5
|
+
mut_step :s1
|
6
|
+
mut_step :s2
|
7
|
+
mut_step :s3
|
8
|
+
mut_step :s4
|
9
|
+
mut_step :s5
|
10
|
+
mut_step :s6
|
11
|
+
mut_step :s7
|
12
|
+
mut_step :s8
|
13
|
+
mut_step :s9
|
14
|
+
mut_step :s10
|
15
|
+
|
16
|
+
def s1(ctx)
|
17
|
+
ctx[:s1] = true
|
18
|
+
end
|
19
|
+
|
20
|
+
def s2(ctx)
|
21
|
+
ctx[:s2] = true
|
22
|
+
end
|
23
|
+
|
24
|
+
def s3(ctx)
|
25
|
+
ctx[:s3] = true
|
26
|
+
end
|
27
|
+
|
28
|
+
def s4(ctx)
|
29
|
+
ctx[:s4] = true
|
30
|
+
end
|
31
|
+
|
32
|
+
def s5(ctx)
|
33
|
+
ctx[:s5] = true
|
34
|
+
end
|
35
|
+
|
36
|
+
def s6(ctx)
|
37
|
+
ctx[:s6] = true
|
38
|
+
end
|
39
|
+
|
40
|
+
def s7(ctx)
|
41
|
+
ctx[:s7] = true
|
42
|
+
end
|
43
|
+
|
44
|
+
def s8(ctx)
|
45
|
+
ctx[:s8] = true
|
46
|
+
end
|
47
|
+
|
48
|
+
def s9(ctx)
|
49
|
+
ctx[:s9] = true
|
50
|
+
end
|
51
|
+
|
52
|
+
def s10(ctx)
|
53
|
+
ctx[:s10] = true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
class BenchmarkCLI
|
2
|
+
module Examples
|
3
|
+
module TenSteps
|
4
|
+
class FlowsSCPOC < Flows::SharedContextPipeline
|
5
|
+
include Flows::Plugin::OutputContract
|
6
|
+
|
7
|
+
step :s1
|
8
|
+
step :s2
|
9
|
+
step :s3
|
10
|
+
step :s4
|
11
|
+
step :s5
|
12
|
+
step :s6
|
13
|
+
step :s7
|
14
|
+
step :s8
|
15
|
+
step :s9
|
16
|
+
step :s10
|
17
|
+
|
18
|
+
success_with :ok do
|
19
|
+
hash_of(
|
20
|
+
s10: true
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def s1(**)
|
25
|
+
ok(s1: true)
|
26
|
+
end
|
27
|
+
|
28
|
+
def s2(s1:, **)
|
29
|
+
ok(s2: true)
|
30
|
+
end
|
31
|
+
|
32
|
+
def s3(s2:, **)
|
33
|
+
ok(s3: true)
|
34
|
+
end
|
35
|
+
|
36
|
+
def s4(s3:, **)
|
37
|
+
ok(s4: true)
|
38
|
+
end
|
39
|
+
|
40
|
+
def s5(s4:, **)
|
41
|
+
ok(s5: true)
|
42
|
+
end
|
43
|
+
|
44
|
+
def s6(s5:, **)
|
45
|
+
ok(s6: true)
|
46
|
+
end
|
47
|
+
|
48
|
+
def s7(s6:, **)
|
49
|
+
ok(s7: true)
|
50
|
+
end
|
51
|
+
|
52
|
+
def s8(s7:, **)
|
53
|
+
ok(s8: true)
|
54
|
+
end
|
55
|
+
|
56
|
+
def s9(s8:, **)
|
57
|
+
ok(s9: true)
|
58
|
+
end
|
59
|
+
|
60
|
+
def s10(s9:, **)
|
61
|
+
ok(s10: true)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'trailblazer/operation'
|
2
|
+
|
3
|
+
class BenchmarkCLI
|
4
|
+
module Examples
|
5
|
+
module TenSteps
|
6
|
+
class TB < Trailblazer::Operation
|
7
|
+
step :s1
|
8
|
+
step :s2
|
9
|
+
step :s3
|
10
|
+
step :s4
|
11
|
+
step :s5
|
12
|
+
step :s6
|
13
|
+
step :s7
|
14
|
+
step :s8
|
15
|
+
step :s9
|
16
|
+
step :s10
|
17
|
+
|
18
|
+
def s1(opts, **)
|
19
|
+
opts[:s1] = true
|
20
|
+
end
|
21
|
+
|
22
|
+
def s2(opts, s1:, **)
|
23
|
+
opts[:s2] = true
|
24
|
+
end
|
25
|
+
|
26
|
+
def s3(opts, s2:, **)
|
27
|
+
opts[:s3] = true
|
28
|
+
end
|
29
|
+
|
30
|
+
def s4(opts, s3:, **)
|
31
|
+
opts[:s4] = true
|
32
|
+
end
|
33
|
+
|
34
|
+
def s5(opts, s4:, **)
|
35
|
+
opts[:s5] = true
|
36
|
+
end
|
37
|
+
|
38
|
+
def s6(opts, s5:, **)
|
39
|
+
opts[:s6] = true
|
40
|
+
end
|
41
|
+
|
42
|
+
def s7(opts, s6:, **)
|
43
|
+
opts[:s7] = true
|
44
|
+
end
|
45
|
+
|
46
|
+
def s8(opts, s7:, **)
|
47
|
+
opts[:s8] = true
|
48
|
+
end
|
49
|
+
|
50
|
+
def s9(opts, s8:, **)
|
51
|
+
opts[:s9] = true
|
52
|
+
end
|
53
|
+
|
54
|
+
def s10(opts, s9:, **)
|
55
|
+
opts[:s10] = true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative 'ruby/structs'
|
2
|
+
require_relative 'ruby/method_exec'
|
3
|
+
require_relative 'ruby/self_class'
|
4
|
+
|
5
|
+
require_relative 'ruby/command'
|
6
|
+
|
7
|
+
class BenchmarkCLI
|
8
|
+
module Ruby
|
9
|
+
BENCHMARKS = {
|
10
|
+
structs: Structs,
|
11
|
+
method_exec: MethodExec,
|
12
|
+
self_class: SelfClass
|
13
|
+
}.freeze
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class BenchmarkCLI
|
2
|
+
module Ruby
|
3
|
+
class Command
|
4
|
+
include Flows::Result::Helpers
|
5
|
+
extend Flows::Result::Do
|
6
|
+
|
7
|
+
attr_reader :benchmarks
|
8
|
+
|
9
|
+
def initialize(benchmarks)
|
10
|
+
@benchmarks = benchmarks.map(&:to_sym)
|
11
|
+
end
|
12
|
+
|
13
|
+
do_notation(:call)
|
14
|
+
def call
|
15
|
+
yield validate
|
16
|
+
run
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def validate
|
22
|
+
benchmarks.each do |benchmark|
|
23
|
+
return err_data("Unexpected benchmark: #{benchmark}") unless BENCHMARKS.key?(benchmark)
|
24
|
+
end
|
25
|
+
|
26
|
+
ok
|
27
|
+
end
|
28
|
+
|
29
|
+
def run
|
30
|
+
benchmarks.each do |benchmark|
|
31
|
+
BENCHMARKS[benchmark].new.call
|
32
|
+
end
|
33
|
+
|
34
|
+
ok
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
class BenchmarkCLI
|
2
|
+
module Ruby
|
3
|
+
class MethodExec
|
4
|
+
include Helpers
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@instance = OneMethod.new
|
8
|
+
@method_obj = @instance.method(:meth)
|
9
|
+
@lambda = -> { :ok }
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
header 'Different method execution ways'
|
14
|
+
|
15
|
+
Benchmark.ips do |benchmark|
|
16
|
+
benchmark.config(stats: :bootstrap, confidence: 95)
|
17
|
+
|
18
|
+
run_benchmarks(benchmark)
|
19
|
+
|
20
|
+
benchmark.compare!
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class OneMethod
|
25
|
+
def meth
|
26
|
+
:ok
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def run_benchmarks(benchmark)
|
33
|
+
report_method_call(benchmark)
|
34
|
+
report_public_send(benchmark)
|
35
|
+
report_send(benchmark)
|
36
|
+
report_method_object(benchmark)
|
37
|
+
report_lambda_call(benchmark)
|
38
|
+
end
|
39
|
+
|
40
|
+
def report_method_call(benchmark)
|
41
|
+
benchmark.report 'Call a method on an instance' do
|
42
|
+
@instance.meth
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def report_public_send(benchmark)
|
47
|
+
benchmark.report 'Call a method using #public_send' do
|
48
|
+
@instance.public_send(:meth)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def report_send(benchmark)
|
53
|
+
benchmark.report 'Call a method using #send' do
|
54
|
+
@instance.send(:meth)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def report_method_object(benchmark)
|
59
|
+
benchmark.report 'Execute an extracted via #method(name) method object' do
|
60
|
+
@method_obj.call
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def report_lambda_call(benchmark)
|
65
|
+
benchmark.report 'Execute a simple lambda' do
|
66
|
+
@lambda.call
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|