flows 0.2.0 → 0.6.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.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/{build.yml → test.yml} +5 -10
  3. data/.gitignore +9 -1
  4. data/.mdlrc +1 -1
  5. data/.reek.yml +54 -0
  6. data/.rubocop.yml +26 -7
  7. data/.rubocop_todo.yml +27 -0
  8. data/.ruby-version +1 -1
  9. data/.yardopts +1 -0
  10. data/CHANGELOG.md +81 -0
  11. data/Gemfile +0 -6
  12. data/README.md +167 -363
  13. data/Rakefile +35 -1
  14. data/bin/.rubocop.yml +5 -0
  15. data/bin/all_the_errors +55 -0
  16. data/bin/benchmark +73 -105
  17. data/bin/benchmark_cli/compare.rb +118 -0
  18. data/bin/benchmark_cli/compare/a_plus_b.rb +22 -0
  19. data/bin/benchmark_cli/compare/base.rb +45 -0
  20. data/bin/benchmark_cli/compare/command.rb +47 -0
  21. data/bin/benchmark_cli/compare/ten_steps.rb +22 -0
  22. data/bin/benchmark_cli/examples.rb +23 -0
  23. data/bin/benchmark_cli/examples/.rubocop.yml +22 -0
  24. data/bin/benchmark_cli/examples/a_plus_b/dry_do.rb +23 -0
  25. data/bin/benchmark_cli/examples/a_plus_b/dry_transaction.rb +17 -0
  26. data/bin/benchmark_cli/examples/a_plus_b/flows_do.rb +22 -0
  27. data/bin/benchmark_cli/examples/a_plus_b/flows_railway.rb +13 -0
  28. data/bin/benchmark_cli/examples/a_plus_b/flows_scp.rb +13 -0
  29. data/bin/benchmark_cli/examples/a_plus_b/flows_scp_mut.rb +13 -0
  30. data/bin/benchmark_cli/examples/a_plus_b/flows_scp_oc.rb +21 -0
  31. data/bin/benchmark_cli/examples/a_plus_b/trailblazer.rb +15 -0
  32. data/bin/benchmark_cli/examples/ten_steps/dry_do.rb +70 -0
  33. data/bin/benchmark_cli/examples/ten_steps/dry_transaction.rb +64 -0
  34. data/bin/benchmark_cli/examples/ten_steps/flows_do.rb +69 -0
  35. data/bin/benchmark_cli/examples/ten_steps/flows_railway.rb +58 -0
  36. data/bin/benchmark_cli/examples/ten_steps/flows_scp.rb +58 -0
  37. data/bin/benchmark_cli/examples/ten_steps/flows_scp_mut.rb +58 -0
  38. data/bin/benchmark_cli/examples/ten_steps/flows_scp_oc.rb +66 -0
  39. data/bin/benchmark_cli/examples/ten_steps/trailblazer.rb +60 -0
  40. data/bin/benchmark_cli/helpers.rb +12 -0
  41. data/bin/benchmark_cli/ruby.rb +15 -0
  42. data/bin/benchmark_cli/ruby/command.rb +38 -0
  43. data/bin/benchmark_cli/ruby/method_exec.rb +71 -0
  44. data/bin/benchmark_cli/ruby/self_class.rb +69 -0
  45. data/bin/benchmark_cli/ruby/structs.rb +90 -0
  46. data/bin/console +1 -0
  47. data/bin/docserver +7 -0
  48. data/bin/errors +138 -0
  49. data/bin/errors_cli/contract_error_demo.rb +49 -0
  50. data/bin/errors_cli/di_error_demo.rb +38 -0
  51. data/bin/errors_cli/flow_error_demo.rb +22 -0
  52. data/bin/errors_cli/flows_router_error_demo.rb +15 -0
  53. data/bin/errors_cli/interface_error_demo.rb +17 -0
  54. data/bin/errors_cli/oc_error_demo.rb +40 -0
  55. data/bin/errors_cli/railway_error_demo.rb +10 -0
  56. data/bin/errors_cli/result_error_demo.rb +13 -0
  57. data/bin/errors_cli/scp_error_demo.rb +17 -0
  58. data/docs/README.md +3 -187
  59. data/docs/_sidebar.md +0 -24
  60. data/docs/index.html +1 -1
  61. data/flows.gemspec +27 -2
  62. data/forspell.dict +9 -0
  63. data/lefthook.yml +9 -0
  64. data/lib/flows.rb +11 -5
  65. data/lib/flows/contract.rb +402 -0
  66. data/lib/flows/contract/array.rb +55 -0
  67. data/lib/flows/contract/case_eq.rb +43 -0
  68. data/lib/flows/contract/compose.rb +77 -0
  69. data/lib/flows/contract/either.rb +53 -0
  70. data/lib/flows/contract/error.rb +24 -0
  71. data/lib/flows/contract/hash.rb +75 -0
  72. data/lib/flows/contract/hash_of.rb +70 -0
  73. data/lib/flows/contract/helpers.rb +22 -0
  74. data/lib/flows/contract/predicate.rb +34 -0
  75. data/lib/flows/contract/transformer.rb +50 -0
  76. data/lib/flows/contract/tuple.rb +70 -0
  77. data/lib/flows/flow.rb +96 -7
  78. data/lib/flows/flow/errors.rb +29 -0
  79. data/lib/flows/flow/node.rb +132 -0
  80. data/lib/flows/flow/router.rb +29 -0
  81. data/lib/flows/flow/router/custom.rb +59 -0
  82. data/lib/flows/flow/router/errors.rb +11 -0
  83. data/lib/flows/flow/router/simple.rb +25 -0
  84. data/lib/flows/plugin.rb +15 -0
  85. data/lib/flows/plugin/dependency_injector.rb +170 -0
  86. data/lib/flows/plugin/dependency_injector/dependency.rb +24 -0
  87. data/lib/flows/plugin/dependency_injector/dependency_definition.rb +16 -0
  88. data/lib/flows/plugin/dependency_injector/dependency_list.rb +55 -0
  89. data/lib/flows/plugin/dependency_injector/errors.rb +58 -0
  90. data/lib/flows/plugin/implicit_init.rb +45 -0
  91. data/lib/flows/plugin/interface.rb +84 -0
  92. data/lib/flows/plugin/output_contract.rb +85 -0
  93. data/lib/flows/plugin/output_contract/dsl.rb +48 -0
  94. data/lib/flows/plugin/output_contract/errors.rb +74 -0
  95. data/lib/flows/plugin/output_contract/wrapper.rb +55 -0
  96. data/lib/flows/plugin/profiler.rb +114 -0
  97. data/lib/flows/plugin/profiler/injector.rb +35 -0
  98. data/lib/flows/plugin/profiler/report.rb +48 -0
  99. data/lib/flows/plugin/profiler/report/events.rb +43 -0
  100. data/lib/flows/plugin/profiler/report/flat.rb +41 -0
  101. data/lib/flows/plugin/profiler/report/flat/method_report.rb +80 -0
  102. data/lib/flows/plugin/profiler/report/raw.rb +15 -0
  103. data/lib/flows/plugin/profiler/report/tree.rb +98 -0
  104. data/lib/flows/plugin/profiler/report/tree/calculated_node.rb +116 -0
  105. data/lib/flows/plugin/profiler/report/tree/node.rb +34 -0
  106. data/lib/flows/plugin/profiler/wrapper.rb +53 -0
  107. data/lib/flows/railway.rb +140 -34
  108. data/lib/flows/railway/dsl.rb +8 -18
  109. data/lib/flows/railway/errors.rb +8 -12
  110. data/lib/flows/railway/step.rb +24 -0
  111. data/lib/flows/railway/step_list.rb +38 -0
  112. data/lib/flows/result.rb +188 -2
  113. data/lib/flows/result/do.rb +158 -16
  114. data/lib/flows/result/err.rb +12 -6
  115. data/lib/flows/result/errors.rb +29 -17
  116. data/lib/flows/result/helpers.rb +25 -3
  117. data/lib/flows/result/ok.rb +12 -6
  118. data/lib/flows/shared_context_pipeline.rb +342 -0
  119. data/lib/flows/shared_context_pipeline/dsl.rb +12 -0
  120. data/lib/flows/shared_context_pipeline/dsl/callbacks.rb +35 -0
  121. data/lib/flows/shared_context_pipeline/dsl/tracks.rb +52 -0
  122. data/lib/flows/shared_context_pipeline/errors.rb +17 -0
  123. data/lib/flows/shared_context_pipeline/mutation_step.rb +30 -0
  124. data/lib/flows/shared_context_pipeline/router_definition.rb +21 -0
  125. data/lib/flows/shared_context_pipeline/step.rb +55 -0
  126. data/lib/flows/shared_context_pipeline/track.rb +54 -0
  127. data/lib/flows/shared_context_pipeline/track_list.rb +51 -0
  128. data/lib/flows/shared_context_pipeline/wrap.rb +73 -0
  129. data/lib/flows/util.rb +17 -0
  130. data/lib/flows/util/inheritable_singleton_vars.rb +86 -0
  131. data/lib/flows/util/inheritable_singleton_vars/dup_strategy.rb +100 -0
  132. data/lib/flows/util/inheritable_singleton_vars/isolation_strategy.rb +91 -0
  133. data/lib/flows/util/prepend_to_class.rb +191 -0
  134. data/lib/flows/version.rb +1 -1
  135. metadata +253 -38
  136. data/Gemfile.lock +0 -174
  137. data/bin/demo +0 -66
  138. data/bin/examples.rb +0 -195
  139. data/bin/profile_10steps +0 -106
  140. data/bin/ruby_benchmarks +0 -26
  141. data/docs/CNAME +0 -1
  142. data/docs/contributing/benchmarks_profiling.md +0 -3
  143. data/docs/contributing/local_development.md +0 -3
  144. data/docs/flow/direct_usage.md +0 -3
  145. data/docs/flow/general_idea.md +0 -3
  146. data/docs/operation/basic_usage.md +0 -1
  147. data/docs/operation/inject_steps.md +0 -3
  148. data/docs/operation/lambda_steps.md +0 -3
  149. data/docs/operation/result_shapes.md +0 -3
  150. data/docs/operation/routing_tracks.md +0 -3
  151. data/docs/operation/wrapping_steps.md +0 -3
  152. data/docs/overview/performance.md +0 -336
  153. data/docs/railway/basic_usage.md +0 -232
  154. data/docs/result_objects/basic_usage.md +0 -196
  155. data/docs/result_objects/do_notation.md +0 -139
  156. data/lib/flows/node.rb +0 -27
  157. data/lib/flows/operation.rb +0 -52
  158. data/lib/flows/operation/builder.rb +0 -130
  159. data/lib/flows/operation/builder/build_router.rb +0 -37
  160. data/lib/flows/operation/dsl.rb +0 -93
  161. data/lib/flows/operation/errors.rb +0 -75
  162. data/lib/flows/operation/executor.rb +0 -78
  163. data/lib/flows/railway/builder.rb +0 -68
  164. data/lib/flows/railway/executor.rb +0 -23
  165. data/lib/flows/result_router.rb +0 -14
  166. 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,12 @@
1
+ class BenchmarkCLI
2
+ module Helpers
3
+ def header(text)
4
+ width = text.size + 4
5
+
6
+ puts '#' * width
7
+ puts "# #{text} #"
8
+ puts '#' * width
9
+ puts
10
+ end
11
+ end
12
+ 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