flows 0.2.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
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,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,22 @@
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
20
+
21
+ Metrics/AbcSize:
22
+ 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,17 @@
1
+ require 'dry/transaction'
2
+
3
+ class BenchmarkCLI
4
+ module Examples
5
+ module APlusB
6
+ class DryTransaction
7
+ include Dry::Transaction
8
+
9
+ step :calculation
10
+
11
+ def calculation(a:, b:)
12
+ Success(a + b)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ 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,13 @@
1
+ class BenchmarkCLI
2
+ module Examples
3
+ module APlusB
4
+ class FlowsRailway < Flows::Railway
5
+ step :calculation
6
+
7
+ def calculation(a:, b:)
8
+ ok(sum: a + b)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ class BenchmarkCLI
2
+ module Examples
3
+ module APlusB
4
+ class FlowsSCP < Flows::SharedContextPipeline
5
+ step :calculation
6
+
7
+ def calculation(a:, b:)
8
+ ok(sum: a + b)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ class BenchmarkCLI
2
+ module Examples
3
+ module APlusB
4
+ class FlowsSCPMut < Flows::SharedContextPipeline
5
+ mut_step :calculation
6
+
7
+ def calculation(ctx)
8
+ ctx[:cum] = ctx[:a] + ctx[:b]
9
+ end
10
+ end
11
+ end
12
+ end
13
+ 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,15 @@
1
+ require 'trailblazer/operation'
2
+
3
+ class BenchmarkCLI
4
+ module Examples
5
+ module APlusB
6
+ class TB < ::Trailblazer::Operation
7
+ step :calculation
8
+
9
+ def calculation(opts, a:, b:)
10
+ opts[:sum] = a + b
11
+ end
12
+ end
13
+ end
14
+ end
15
+ 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