trailblazer-future 2.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.travis.yml +6 -0
  4. data/CHANGES.md +4 -0
  5. data/LICENSE.txt +9 -0
  6. data/README.md +48 -0
  7. data/Rakefile +10 -0
  8. data/bin/console +14 -0
  9. data/bin/setup +8 -0
  10. data/gems.rb +3 -0
  11. data/lib/trailblazer/future.rb +9 -0
  12. data/lib/trailblazer/future/version.rb +5 -0
  13. data/lib/trailblazer/v2_1/activity.rb +123 -0
  14. data/lib/trailblazer/v2_1/activity/config.rb +37 -0
  15. data/lib/trailblazer/v2_1/activity/dsl/add_task.rb +22 -0
  16. data/lib/trailblazer/v2_1/activity/dsl/helper.rb +68 -0
  17. data/lib/trailblazer/v2_1/activity/dsl/magnetic.rb +36 -0
  18. data/lib/trailblazer/v2_1/activity/dsl/magnetic/builder.rb +101 -0
  19. data/lib/trailblazer/v2_1/activity/dsl/magnetic/builder/default_normalizer.rb +26 -0
  20. data/lib/trailblazer/v2_1/activity/dsl/magnetic/builder/fast_track.rb +118 -0
  21. data/lib/trailblazer/v2_1/activity/dsl/magnetic/builder/normalizer.rb +113 -0
  22. data/lib/trailblazer/v2_1/activity/dsl/magnetic/builder/path.rb +105 -0
  23. data/lib/trailblazer/v2_1/activity/dsl/magnetic/builder/railway.rb +97 -0
  24. data/lib/trailblazer/v2_1/activity/dsl/magnetic/builder/state.rb +58 -0
  25. data/lib/trailblazer/v2_1/activity/dsl/magnetic/finalizer.rb +51 -0
  26. data/lib/trailblazer/v2_1/activity/dsl/magnetic/generate.rb +62 -0
  27. data/lib/trailblazer/v2_1/activity/dsl/magnetic/merge.rb +16 -0
  28. data/lib/trailblazer/v2_1/activity/dsl/magnetic/process_options.rb +76 -0
  29. data/lib/trailblazer/v2_1/activity/dsl/magnetic/structure/alterations.rb +44 -0
  30. data/lib/trailblazer/v2_1/activity/dsl/magnetic/structure/plus_poles.rb +85 -0
  31. data/lib/trailblazer/v2_1/activity/dsl/magnetic/structure/polarization.rb +23 -0
  32. data/lib/trailblazer/v2_1/activity/dsl/record.rb +11 -0
  33. data/lib/trailblazer/v2_1/activity/dsl/schema/dependencies.rb +46 -0
  34. data/lib/trailblazer/v2_1/activity/dsl/schema/sequence.rb +46 -0
  35. data/lib/trailblazer/v2_1/activity/dsl/strategy/build_state.rb +32 -0
  36. data/lib/trailblazer/v2_1/activity/dsl/strategy/fast_track.rb +24 -0
  37. data/lib/trailblazer/v2_1/activity/dsl/strategy/path.rb +26 -0
  38. data/lib/trailblazer/v2_1/activity/dsl/strategy/plan.rb +36 -0
  39. data/lib/trailblazer/v2_1/activity/dsl/strategy/railway.rb +23 -0
  40. data/lib/trailblazer/v2_1/activity/interface.rb +16 -0
  41. data/lib/trailblazer/v2_1/activity/introspect.rb +167 -0
  42. data/lib/trailblazer/v2_1/activity/present.rb +95 -0
  43. data/lib/trailblazer/v2_1/activity/structures.rb +57 -0
  44. data/lib/trailblazer/v2_1/activity/task_builder.rb +41 -0
  45. data/lib/trailblazer/v2_1/activity/task_wrap.rb +40 -0
  46. data/lib/trailblazer/v2_1/activity/task_wrap/call_task.rb +19 -0
  47. data/lib/trailblazer/v2_1/activity/task_wrap/merge.rb +23 -0
  48. data/lib/trailblazer/v2_1/activity/task_wrap/runner.rb +62 -0
  49. data/lib/trailblazer/v2_1/activity/task_wrap/trace.rb +44 -0
  50. data/lib/trailblazer/v2_1/activity/task_wrap/variable_mapping.rb +162 -0
  51. data/lib/trailblazer/v2_1/activity/testing.rb +32 -0
  52. data/lib/trailblazer/v2_1/activity/trace.rb +97 -0
  53. data/lib/trailblazer/v2_1/circuit.rb +71 -0
  54. data/lib/trailblazer/v2_1/container_chain.rb +45 -0
  55. data/lib/trailblazer/v2_1/context.rb +79 -0
  56. data/lib/trailblazer/v2_1/deprecation/call.rb +46 -0
  57. data/lib/trailblazer/v2_1/deprecation/context.rb +43 -0
  58. data/lib/trailblazer/v2_1/dsl.rb +47 -0
  59. data/lib/trailblazer/v2_1/macro.rb +11 -0
  60. data/lib/trailblazer/v2_1/macro/contract.rb +5 -0
  61. data/lib/trailblazer/v2_1/operation.rb +91 -0
  62. data/lib/trailblazer/v2_1/operation/auto_inject.rb +47 -0
  63. data/lib/trailblazer/v2_1/operation/callable.rb +42 -0
  64. data/lib/trailblazer/v2_1/operation/class_dependencies.rb +25 -0
  65. data/lib/trailblazer/v2_1/operation/contract.rb +61 -0
  66. data/lib/trailblazer/v2_1/operation/deprecated_macro.rb +19 -0
  67. data/lib/trailblazer/v2_1/operation/deprecations.rb +21 -0
  68. data/lib/trailblazer/v2_1/operation/guard.rb +18 -0
  69. data/lib/trailblazer/v2_1/operation/heritage.rb +30 -0
  70. data/lib/trailblazer/v2_1/operation/inject.rb +36 -0
  71. data/lib/trailblazer/v2_1/operation/inspect.rb +79 -0
  72. data/lib/trailblazer/v2_1/operation/model.rb +50 -0
  73. data/lib/trailblazer/v2_1/operation/module.rb +29 -0
  74. data/lib/trailblazer/v2_1/operation/nested.rb +98 -0
  75. data/lib/trailblazer/v2_1/operation/persist.rb +14 -0
  76. data/lib/trailblazer/v2_1/operation/policy.rb +44 -0
  77. data/lib/trailblazer/v2_1/operation/public_call.rb +55 -0
  78. data/lib/trailblazer/v2_1/operation/pundit.rb +38 -0
  79. data/lib/trailblazer/v2_1/operation/railway.rb +32 -0
  80. data/lib/trailblazer/v2_1/operation/railway/fast_track.rb +13 -0
  81. data/lib/trailblazer/v2_1/operation/railway/macaroni.rb +23 -0
  82. data/lib/trailblazer/v2_1/operation/railway/normalizer.rb +58 -0
  83. data/lib/trailblazer/v2_1/operation/railway/task_builder.rb +37 -0
  84. data/lib/trailblazer/v2_1/operation/rescue.rb +42 -0
  85. data/lib/trailblazer/v2_1/operation/responder.rb +18 -0
  86. data/lib/trailblazer/v2_1/operation/result.rb +30 -0
  87. data/lib/trailblazer/v2_1/operation/test.rb +17 -0
  88. data/lib/trailblazer/v2_1/operation/trace.rb +46 -0
  89. data/lib/trailblazer/v2_1/operation/validate.rb +76 -0
  90. data/lib/trailblazer/v2_1/operation/wrap.rb +83 -0
  91. data/lib/trailblazer/v2_1/option.rb +78 -0
  92. data/lib/trailblazer/v2_1/rails.rb +12 -0
  93. data/lib/trailblazer/v2_1/rails/cell.rb +22 -0
  94. data/lib/trailblazer/v2_1/rails/controller.rb +66 -0
  95. data/lib/trailblazer/v2_1/rails/form.rb +21 -0
  96. data/lib/trailblazer/v2_1/rails/railtie.rb +31 -0
  97. data/lib/trailblazer/v2_1/rails/railtie/extend_application_controller.rb +28 -0
  98. data/lib/trailblazer/v2_1/rails/railtie/loader.rb +58 -0
  99. data/lib/trailblazer/v2_1/rails/test/integration.rb +6 -0
  100. data/lib/trailblazer/v2_1/versions.txt +7 -0
  101. data/test/rails5.0/.gitignore +17 -0
  102. data/test/rails5.0/Gemfile +21 -0
  103. data/test/rails5.0/Rakefile +3 -0
  104. data/test/rails5.0/app/concepts/artist/cell/dashboard.rb +7 -0
  105. data/test/rails5.0/app/concepts/artist/cell/show.rb +4 -0
  106. data/test/rails5.0/app/concepts/artist/view/dashboard.erb +4 -0
  107. data/test/rails5.0/app/concepts/artist/view/show.erb +1 -0
  108. data/test/rails5.0/app/concepts/params/operation/with_args.rb +5 -0
  109. data/test/rails5.0/app/concepts/song/contract/form.rb +6 -0
  110. data/test/rails5.0/app/concepts/song/operation/create.rb +15 -0
  111. data/test/rails5.0/app/concepts/song/operation/show.rb +3 -0
  112. data/test/rails5.0/app/concepts/song/operation/update.rb +15 -0
  113. data/test/rails5.0/app/controllers/application_controller.rb +46 -0
  114. data/test/rails5.0/app/controllers/args_controller.rb +5 -0
  115. data/test/rails5.0/app/controllers/artists_controller.rb +24 -0
  116. data/test/rails5.0/app/controllers/params_controller.rb +11 -0
  117. data/test/rails5.0/app/controllers/songs_controller.rb +35 -0
  118. data/test/rails5.0/app/models/artist.rb +2 -0
  119. data/test/rails5.0/app/models/song.rb +2 -0
  120. data/test/rails5.0/app/views/args/with_args.html.erb +1 -0
  121. data/test/rails5.0/app/views/layouts/application.html.erb +2 -0
  122. data/test/rails5.0/app/views/songs/edit.html.erb +4 -0
  123. data/test/rails5.0/app/views/songs/new.html.erb +5 -0
  124. data/test/rails5.0/app/views/songs/new_with_result.html.erb +3 -0
  125. data/test/rails5.0/app/views/songs/show.html.erb +3 -0
  126. data/test/rails5.0/bin/bundle +3 -0
  127. data/test/rails5.0/bin/rails +4 -0
  128. data/test/rails5.0/bin/rake +4 -0
  129. data/test/rails5.0/bin/setup +29 -0
  130. data/test/rails5.0/config.ru +4 -0
  131. data/test/rails5.0/config/application.rb +25 -0
  132. data/test/rails5.0/config/boot.rb +3 -0
  133. data/test/rails5.0/config/database.yml +21 -0
  134. data/test/rails5.0/config/environment.rb +5 -0
  135. data/test/rails5.0/config/environments/development.rb +41 -0
  136. data/test/rails5.0/config/environments/test.rb +42 -0
  137. data/test/rails5.0/config/initializers/assets.rb +11 -0
  138. data/test/rails5.0/config/initializers/backtrace_silencers.rb +7 -0
  139. data/test/rails5.0/config/initializers/cookies_serializer.rb +3 -0
  140. data/test/rails5.0/config/initializers/filter_parameter_logging.rb +4 -0
  141. data/test/rails5.0/config/initializers/inflections.rb +16 -0
  142. data/test/rails5.0/config/initializers/mime_types.rb +4 -0
  143. data/test/rails5.0/config/initializers/session_store.rb +3 -0
  144. data/test/rails5.0/config/initializers/wrap_parameters.rb +14 -0
  145. data/test/rails5.0/config/locales/en.yml +23 -0
  146. data/test/rails5.0/config/routes.rb +15 -0
  147. data/test/rails5.0/config/secrets.yml +17 -0
  148. data/test/rails5.0/db/migrate/20161122145124_create_songs.rb +8 -0
  149. data/test/rails5.0/db/schema.rb +19 -0
  150. data/test/rails5.0/log/.keep +0 -0
  151. data/test/rails5.0/test/concepts/song/operation/create_test.rb +11 -0
  152. data/test/rails5.0/test/concepts/song/operation/update_test.rb +34 -0
  153. data/test/rails5.0/test/integration/.keep +0 -0
  154. data/test/rails5.0/test/integration/args_controller_test.rb +8 -0
  155. data/test/rails5.0/test/integration/artists_controller_test.rb +28 -0
  156. data/test/rails5.0/test/integration/params_controller_test.rb +8 -0
  157. data/test/rails5.0/test/integration/songs_controller_test.rb +40 -0
  158. data/test/rails5.0/test/test_helper.rb +7 -0
  159. data/test/test_helper.rb +5 -0
  160. data/trailblazer-future.gemspec +25 -0
  161. metadata +246 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8fbd09ac23c1b1b27633ad25bd1da7375c58987cc9d705aaa3cad826f5bd5467
4
+ data.tar.gz: a99e5277b29b7d2423ed106494ce5939c9f29789aae9571c32fdfdfd80a21719
5
+ SHA512:
6
+ metadata.gz: cf4d9f163f3a7b43638fc9b5a7a50eaadd36c3bbe6c29946748c9cd69dcedba7fab0399982b05456a3bdbfb4efd97986f15eb03dba60011d330f35e9e53dd204
7
+ data.tar.gz: a697eacd1a5fb4997903a7ad362710bf0fa12e76aaf60dc6a6ce084a37c36c019dbdbb514bf18caa00c403578a15bcb014dae85a23b35638bc3d964a5f5dc56a
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .idea
10
+ *.iml
11
+ gems.locked
12
+ test/**/Gemfile.lock
@@ -0,0 +1,6 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.3
5
+ before_install: gem install bundler -v 1.16.1
6
+ script: cd test/rails5.0 && bundle && rake
@@ -0,0 +1,4 @@
1
+ # 2.1.0.rc1
2
+
3
+ * First release (check trailblazer/v2_1/versions.txt)
4
+
@@ -0,0 +1,9 @@
1
+ Copyright (c) 2018 Trailblazer GmbH
2
+
3
+ Trailblazer is an Open Source project licensed under the terms of
4
+ the LGPLv3 license. Please see <http://www.gnu.org/licenses/lgpl-3.0.html>
5
+ for license text.
6
+
7
+ Trailblazer Enterprise has a commercial-friendly license allowing private forks
8
+ and modifications of Trailblazer. Please see http://trailblazer.to/enterprise/ for
9
+ more detail. You can find the commercial license terms in COMM-LICENSE.
@@ -0,0 +1,48 @@
1
+ # Trailblazer::Future
2
+ [![Build Status](https://travis-ci.org/trailblazer/trailblazer-future.svg)](https://travis-ci.org/trailblazer/trailblazer-future)
3
+ [![Gem Version](https://badge.fury.io/rb/trailblazer-future.svg)](http://badge.fury.io/rb/trailblazer-future)
4
+
5
+ ## Installation
6
+
7
+ - Step 1
8
+
9
+ Update `trailblazer` to it latest patch version `~> 2.0.7`
10
+
11
+ - Step 2
12
+
13
+ Test your build and remove any deprecation warning
14
+
15
+ - Optional step (recommended)
16
+
17
+ Feed a homeless person
18
+
19
+ - Step 3
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'trailblazer-future'
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ 1) Inherit operation from `Trailblazer::V2_1::Operation`
30
+ ```ruby
31
+ class MyOP < Trailblazer::V2_1::Operation
32
+ end
33
+ ```
34
+ 2) Migrate to TRB 2.1 following the [migration path](http://trailblazer.to/api-docs/#trailblazer-migration-path), here a quick summary of the breaking changes:
35
+ - new API using keyword arguments: `MyOP.(params)` -> `MyOp.(params: params)` (more [here](http://trailblazer.to/api-docs/#operation-call))
36
+ - using `symbol` instead of `string` for `:model` and `:current_user`: `result['model']` -> `result[:model]`
37
+ - Replace `Railway::Right/Left` with `Trailblazer::Activity::Right/Left`
38
+ - Add option `fast_track: true` for the steps that uses `pass_fast!` or `fail_fast!` (check the new [wiring API](http://trailblazer.to/api-docs/#activity-wiring-api))
39
+ - Nested macro now gets the all result object so use `:input` and `:output` to filter data in/out
40
+
41
+ ## Notes
42
+
43
+ 1) Operations of different versions cannot be nested
44
+ 2) Rails controller's `run` is for V2.0. Use `run_v21` for the migrated operations
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "trailblazer/future"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/gems.rb ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ gemspec
@@ -0,0 +1,9 @@
1
+ require "trailblazer/future/version"
2
+ require "trailblazer"
3
+ require "trailblazer/v2_1/macro"
4
+ require "trailblazer/v2_1/macro/contract"
5
+ require "trailblazer/v2_1/dsl"
6
+
7
+ require "trailblazer/v2_1/operation/deprecations"
8
+ require "trailblazer/v2_1/operation/inject"
9
+
@@ -0,0 +1,5 @@
1
+ module Trailblazer
2
+ module Future
3
+ VERSION = "2.1.0.rc1"
4
+ end
5
+ end
@@ -0,0 +1,123 @@
1
+ module Trailblazer::V2_1
2
+ class Activity < Module
3
+ attr_reader :initial_state
4
+
5
+ def initialize(implementation, options)
6
+ builder, adds, circuit, outputs, options = BuildState.build_state_for( implementation.config, options)
7
+
8
+ @initial_state = State::Config.build(
9
+ builder: builder,
10
+ options: options,
11
+ adds: adds,
12
+ circuit: circuit,
13
+ outputs: outputs,
14
+ )
15
+
16
+ include *options[:extend] # include the DSL methods.
17
+ include PublicAPI
18
+ end
19
+
20
+ # Injects the initial configuration into the module defining a new activity.
21
+ def extended(extended)
22
+ super
23
+ extended.instance_variable_set(:@state, initial_state)
24
+ end
25
+
26
+
27
+ module Inspect
28
+ def inspect
29
+ "#<Trailblazer::V2_1::Activity: {#{name || self[:options][:name]}}>"
30
+ end
31
+
32
+ alias_method :to_s, :inspect
33
+ end
34
+
35
+
36
+ require "trailblazer/v2_1/activity/dsl/helper"
37
+ # Helpers such as Path, Output, End to be included into {Activity}.
38
+ module DSLHelper
39
+ extend Forwardable
40
+ def_delegators :@builder, :Path
41
+ def_delegators DSL, :Output, :End, :Subprocess, :Track
42
+
43
+ def Path(*args, &block)
44
+ self[:builder].Path(*args, &block)
45
+ end
46
+ end
47
+
48
+ # Reader and writer method for DSL objects.
49
+ # The writer {dsl[:key] = "value"} exposes immutable behavior and will replace the old
50
+ # @state with a new, modified copy.
51
+ #
52
+ # Always use the DSL::Accessor accessors to avoid leaking state to other components
53
+ # due to mutable write operations.
54
+ module Accessor
55
+ def []=(*args)
56
+ @state = State::Config.send(:[]=, @state, *args)
57
+ end
58
+
59
+ def [](*args)
60
+ State::Config[@state, *args]
61
+ end
62
+ end
63
+
64
+ # FIXME: still to be decided
65
+ # By including those modules, we create instance methods.
66
+ # Later, this module is `extended` in Path, Railway and FastTrack, and
67
+ # imports the DSL methods as class methods.
68
+ module PublicAPI
69
+ include Accessor
70
+
71
+ require "trailblazer/v2_1/activity/dsl/add_task"
72
+ include DSL::AddTask
73
+
74
+ require "trailblazer/v2_1/activity/interface"
75
+ include Activity::Interface # DISCUSS
76
+
77
+ include DSLHelper # DISCUSS
78
+
79
+ include Activity::Inspect # DISCUSS
80
+
81
+ require "trailblazer/v2_1/activity/dsl/magnetic/merge"
82
+ include Magnetic::Merge # Activity#merge!
83
+
84
+ # @private Note that {Activity.call} is considered private until the public API is stable.
85
+ def call(args, circuit_options={})
86
+ self[:circuit].( args, circuit_options.merge(activity: self) )
87
+ end
88
+ end
89
+
90
+ end # Activity
91
+ end
92
+
93
+ require "trailblazer/v2_1/circuit"
94
+ require "trailblazer/v2_1/activity/structures"
95
+ require "trailblazer/v2_1/activity/config"
96
+
97
+ require "trailblazer/v2_1/activity/dsl/strategy/build_state"
98
+ require "trailblazer/v2_1/activity/dsl/strategy/path"
99
+ require "trailblazer/v2_1/activity/dsl/strategy/plan"
100
+ require "trailblazer/v2_1/activity/dsl/strategy/railway"
101
+ require "trailblazer/v2_1/activity/dsl/strategy/fast_track"
102
+
103
+ require "trailblazer/v2_1/activity/task_wrap"
104
+ require "trailblazer/v2_1/activity/task_wrap/call_task"
105
+ require "trailblazer/v2_1/activity/task_wrap/trace"
106
+ require "trailblazer/v2_1/activity/task_wrap/runner"
107
+ require "trailblazer/v2_1/activity/task_wrap/merge"
108
+ require "trailblazer/v2_1/activity/task_wrap/variable_mapping"
109
+
110
+ require "trailblazer/v2_1/activity/trace"
111
+ require "trailblazer/v2_1/activity/present"
112
+
113
+ require "trailblazer/v2_1/activity/introspect"
114
+
115
+ require "trailblazer/v2_1/activity/dsl/magnetic/builder/state"
116
+ require "trailblazer/v2_1/activity/dsl/magnetic" # the "magnetic" DSL
117
+
118
+ require "trailblazer/v2_1/activity/dsl/schema/sequence"
119
+ require "trailblazer/v2_1/activity/dsl/schema/dependencies"
120
+
121
+ require "trailblazer/v2_1/activity/dsl/magnetic/builder/normalizer" # DISCUSS: name and location are odd. This one uses Activity ;)
122
+
123
+ require "trailblazer/v2_1/activity/dsl/record"
@@ -0,0 +1,37 @@
1
+ module Trailblazer::V2_1
2
+ module Activity::State
3
+ # Compile-time
4
+ #
5
+ # DISCUSS: we could replace parts with Hamster::Hash.
6
+ class Config
7
+ def self.build(variables={})
8
+ Hash[ variables.collect { |k,v| [k, v.freeze] } ].freeze
9
+ end
10
+
11
+ def self.[]=(state, *args)
12
+ if args.size == 2
13
+ key, value = *args
14
+
15
+ state = state.merge(key => value)
16
+ else
17
+ directive, key, value = *args
18
+
19
+ state = state.merge( directive => {}.freeze ) unless state.key?(directive)
20
+
21
+ directive_hash = state[directive].merge(key => value)
22
+ state = state.merge( directive => directive_hash.freeze )
23
+ end
24
+
25
+ state
26
+ end
27
+
28
+ def self.[](state, *args)
29
+ directive, key = *args
30
+
31
+ return state[directive] if args.size == 1
32
+ return state[directive][key] if state.key?(directive)
33
+ nil
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,22 @@
1
+ class Trailblazer::V2_1::Activity < Module
2
+ module DSL
3
+ module AddTask
4
+ def add_task!(strategy, polarizer, name, task, options, &block)
5
+ # The beautiful thing about State.add is it doesn't mutate anything.
6
+ # We're changing state here, on the outside, by overriding the ivars.
7
+ # That in turn means, the only mutated entity is this module.
8
+
9
+ _builder, adds, circuit, outputs, returned_options = Magnetic::Builder::State.add( self[:builder], self[:adds], strategy, polarizer, task, options, &block ) # this could be an extension itself.
10
+
11
+ self[:adds] = adds
12
+ self[:circuit] = circuit
13
+ self[:outputs] = outputs
14
+
15
+ _, local_options, connections, sequence_options, extension_options = returned_options
16
+
17
+ # {Extension API} call all extensions.
18
+ extension_options.keys.collect { |ext| ext.( self, *returned_options, original_dsl_args: [name, task, options, block] ) }
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,68 @@
1
+ module Trailblazer::V2_1
2
+ module Activity::DSL
3
+ # Create a new method (e.g. Activity::step) that delegates to its builder, recompiles
4
+ # the circuit, etc. Method comes in a module so it can be overridden via modules.
5
+ #
6
+ # This approach assumes you maintain a {#add_task!} method.
7
+ def self.def_dsl(_name, strategy, polarizer)
8
+ Module.new do
9
+ define_method(_name) do |task, options={}, &block|
10
+ builder, adds, circuit, outputs, options = add_task!(strategy, polarizer, _name, task, options, &block)
11
+ end
12
+ end
13
+ end
14
+
15
+ # @api private
16
+ OutputSemantic = Struct.new(:value)
17
+ Track = Struct.new(:color)
18
+ Extension = Struct.new(:callable) do
19
+ def call(*args, &block)
20
+ callable.(*args, &block)
21
+ end
22
+ end
23
+
24
+ # Shortcut functions for the DSL. These have no state.
25
+ module_function
26
+
27
+ # Output( Left, :failure )
28
+ # Output( :failure ) #=> Output::Semantic
29
+ def Output(signal, semantic=nil)
30
+ return OutputSemantic.new(signal) if semantic.nil?
31
+
32
+ Activity.Output(signal, semantic)
33
+ end
34
+
35
+ def End(semantic)
36
+ Activity.End(semantic)
37
+ end
38
+
39
+ def Track(color)
40
+ Track.new(color).freeze
41
+ end
42
+
43
+ def Path(normalizer, track_color: "track_#{rand}", end_semantic: track_color, **options)
44
+ options = options.merge(track_color: track_color, end_semantic: end_semantic)
45
+
46
+ # Build an anonymous class which will be where the block is evaluated in.
47
+ # We use the same normalizer here, so DSL calls in the inner block have the same behavior.
48
+ path = Module.new do
49
+ extend Activity::Path( options.merge( normalizer: normalizer ) )
50
+ end
51
+
52
+ # this block is called in DSL::ProcessTuples. This could be improved somehow.
53
+ ->(block) {
54
+ path.instance_exec(&block)
55
+
56
+ [ track_color, path ]
57
+ }
58
+ end
59
+
60
+ # Computes the :outputs options for {activity}
61
+ def Subprocess(activity)
62
+ {
63
+ task: activity,
64
+ outputs: activity.outputs
65
+ }
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,36 @@
1
+ module Trailblazer::V2_1
2
+ class Activity < Module # all code related to the magnetic building of a circuit hash lives in this namespace.
3
+ module Magnetic
4
+ # PlusPole "radiates" a color that MinusPoles are attracted to.
5
+ #
6
+ # This datastructure is produced by the DSL and sits in an ADDS.
7
+ PlusPole = Struct.new(:output, :color) do
8
+ private :output
9
+
10
+ def signal
11
+ output.signal
12
+ end
13
+ end # PlusPole
14
+ end
15
+ end
16
+ end
17
+
18
+ require "trailblazer/v2_1/activity/dsl/magnetic/process_options"
19
+ require "trailblazer/v2_1/activity/dsl/magnetic/structure/plus_poles"
20
+ require "trailblazer/v2_1/activity/dsl/magnetic/structure/polarization"
21
+ require "trailblazer/v2_1/activity/dsl/magnetic/structure/alterations"
22
+
23
+ require "trailblazer/v2_1/activity/dsl/magnetic"
24
+ require "trailblazer/v2_1/activity/dsl/magnetic/builder"
25
+ # require "trailblazer/v2_1/activity/dsl/magnetic/builder/dsl_helper"
26
+ # require "trailblazer/v2_1/activity/dsl/magnetic/dsl_helper"
27
+
28
+ require "trailblazer/v2_1/option"
29
+ require "trailblazer/v2_1/activity/task_builder"
30
+ require "trailblazer/v2_1/activity/dsl/magnetic/builder/default_normalizer"
31
+ require "trailblazer/v2_1/activity/dsl/magnetic/builder/path"
32
+ require "trailblazer/v2_1/activity/dsl/magnetic/builder/railway"
33
+ require "trailblazer/v2_1/activity/dsl/magnetic/builder/fast_track" # TODO: move to Operation gem.
34
+
35
+ require "trailblazer/v2_1/activity/dsl/magnetic/generate"
36
+ require "trailblazer/v2_1/activity/dsl/magnetic/finalizer"