trailblazer-activity 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop-https---raw-githubusercontent-com-trailblazer-meta-master-rubocop-yml +101 -0
- data/.rubocop.yml +4 -13
- data/.rubocop_todo.yml +474 -476
- data/.travis.yml +3 -2
- data/CHANGES.md +10 -0
- data/Gemfile +5 -4
- data/README.md +2 -0
- data/Rakefile +1 -1
- data/lib/trailblazer/activity.rb +29 -92
- data/lib/trailblazer/activity/circuit.rb +74 -0
- data/lib/trailblazer/activity/config.rb +4 -6
- data/lib/trailblazer/activity/introspect.rb +33 -129
- data/lib/trailblazer/activity/present.rb +14 -39
- data/lib/trailblazer/activity/schema.rb +13 -0
- data/lib/trailblazer/activity/schema/implementation.rb +10 -0
- data/lib/trailblazer/activity/schema/intermediate.rb +94 -0
- data/lib/trailblazer/activity/structures.rb +43 -43
- data/lib/trailblazer/activity/task_wrap.rb +29 -16
- data/lib/trailblazer/activity/task_wrap/call_task.rb +4 -4
- data/lib/trailblazer/activity/task_wrap/inject.rb +37 -0
- data/lib/trailblazer/activity/task_wrap/pipeline.rb +55 -0
- data/lib/trailblazer/activity/task_wrap/runner.rb +10 -19
- data/lib/trailblazer/activity/task_wrap/variable_mapping.rb +25 -97
- data/lib/trailblazer/activity/testing.rb +64 -22
- data/lib/trailblazer/activity/trace.rb +88 -41
- data/lib/trailblazer/activity/version.rb +4 -2
- data/trailblazer-activity.gemspec +5 -9
- metadata +18 -55
- data/lib/trailblazer/activity/dsl/add_task.rb +0 -22
- data/lib/trailblazer/activity/dsl/helper.rb +0 -68
- data/lib/trailblazer/activity/dsl/magnetic.rb +0 -36
- data/lib/trailblazer/activity/dsl/magnetic/builder.rb +0 -101
- data/lib/trailblazer/activity/dsl/magnetic/builder/default_normalizer.rb +0 -26
- data/lib/trailblazer/activity/dsl/magnetic/builder/fast_track.rb +0 -118
- data/lib/trailblazer/activity/dsl/magnetic/builder/normalizer.rb +0 -113
- data/lib/trailblazer/activity/dsl/magnetic/builder/path.rb +0 -105
- data/lib/trailblazer/activity/dsl/magnetic/builder/railway.rb +0 -97
- data/lib/trailblazer/activity/dsl/magnetic/builder/state.rb +0 -58
- data/lib/trailblazer/activity/dsl/magnetic/finalizer.rb +0 -51
- data/lib/trailblazer/activity/dsl/magnetic/generate.rb +0 -62
- data/lib/trailblazer/activity/dsl/magnetic/merge.rb +0 -16
- data/lib/trailblazer/activity/dsl/magnetic/process_options.rb +0 -76
- data/lib/trailblazer/activity/dsl/magnetic/structure/alterations.rb +0 -44
- data/lib/trailblazer/activity/dsl/magnetic/structure/plus_poles.rb +0 -85
- data/lib/trailblazer/activity/dsl/magnetic/structure/polarization.rb +0 -23
- data/lib/trailblazer/activity/dsl/record.rb +0 -11
- data/lib/trailblazer/activity/dsl/schema/dependencies.rb +0 -46
- data/lib/trailblazer/activity/dsl/schema/sequence.rb +0 -46
- data/lib/trailblazer/activity/dsl/strategy/build_state.rb +0 -32
- data/lib/trailblazer/activity/dsl/strategy/fast_track.rb +0 -24
- data/lib/trailblazer/activity/dsl/strategy/path.rb +0 -26
- data/lib/trailblazer/activity/dsl/strategy/plan.rb +0 -36
- data/lib/trailblazer/activity/dsl/strategy/railway.rb +0 -23
- data/lib/trailblazer/activity/interface.rb +0 -16
- data/lib/trailblazer/activity/task_wrap/merge.rb +0 -23
- data/lib/trailblazer/activity/task_wrap/trace.rb +0 -44
- data/lib/trailblazer/circuit.rb +0 -71
@@ -1,23 +0,0 @@
|
|
1
|
-
module Trailblazer
|
2
|
-
# Implementation module that can be passed to `Activity[]`.
|
3
|
-
class Activity < Module
|
4
|
-
def self.Railway(options={})
|
5
|
-
Railway.new(Railway, options)
|
6
|
-
end
|
7
|
-
|
8
|
-
class Railway < Activity
|
9
|
-
def self.config
|
10
|
-
Path.config.merge(
|
11
|
-
builder_class: Magnetic::Builder::Railway,
|
12
|
-
default_outputs: Magnetic::Builder::Path.default_outputs,
|
13
|
-
extend: [
|
14
|
-
DSL.def_dsl(:step, Magnetic::Builder::Railway, :StepPolarizations),
|
15
|
-
DSL.def_dsl(:fail, Magnetic::Builder::Railway, :FailPolarizations),
|
16
|
-
DSL.def_dsl(:pass, Magnetic::Builder::Railway, :PassPolarizations),
|
17
|
-
DSL.def_dsl(:_end, Magnetic::Builder::Path, :EndEventPolarizations), # TODO: TEST ME
|
18
|
-
],
|
19
|
-
)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
class Trailblazer::Activity < Module
|
2
|
-
module Interface
|
3
|
-
# @return [Process, Hash, Adds] Adds is private and should not be used in your application as it might get removed.
|
4
|
-
def to_h # TODO: test me
|
5
|
-
@state.to_h
|
6
|
-
end
|
7
|
-
|
8
|
-
def debug # TODO: TEST ME
|
9
|
-
to_h[:debug]
|
10
|
-
end
|
11
|
-
|
12
|
-
def outputs
|
13
|
-
to_h[:outputs]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Trailblazer
|
2
|
-
module Activity::TaskWrap
|
3
|
-
# This is instantiated via the DSL, and passed to the :extension API,
|
4
|
-
# allowing to add steps to the Activity's static_wrap.
|
5
|
-
# Compile-time function
|
6
|
-
class Merge
|
7
|
-
def initialize(extension_plan)
|
8
|
-
@extension_plan = extension_plan
|
9
|
-
end
|
10
|
-
|
11
|
-
# {:extension API}
|
12
|
-
def call(activity, task, local_options, *returned_options)
|
13
|
-
# we could make the default initial_activity injectable via the DSL, the value would sit in returned_options or local_options.
|
14
|
-
static_wrap = Activity::TaskWrap.wrap_static_for(task, activity: activity)
|
15
|
-
|
16
|
-
# # macro might want to apply changes to the static task_wrap (e.g. Inject)
|
17
|
-
new_wrap = Activity::Path::Plan.merge( static_wrap, @extension_plan )
|
18
|
-
|
19
|
-
activity[:wrap_static, task] = new_wrap
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
class Trailblazer::Activity < Module
|
2
|
-
module TaskWrap
|
3
|
-
# TaskWrap tasks for tracing.
|
4
|
-
module Trace
|
5
|
-
module_function
|
6
|
-
|
7
|
-
# taskWrap step to capture incoming arguments of a step.
|
8
|
-
# def self.capture_args(direction, options, flow_options, wrap_config, original_flow_options)
|
9
|
-
def capture_args((wrap_config, original_args), **circuit_options)
|
10
|
-
|
11
|
-
original_args = capture_for(wrap_config[:task], *original_args)
|
12
|
-
|
13
|
-
return Trailblazer::Activity::Right, [wrap_config, original_args], circuit_options
|
14
|
-
end
|
15
|
-
|
16
|
-
# taskWrap step to capture outgoing arguments from a step.
|
17
|
-
def capture_return((wrap_config, original_args), **circuit_options)
|
18
|
-
(original_options, original_flow_options, _) = original_args[0]
|
19
|
-
|
20
|
-
original_flow_options[:stack] << Trailblazer::Activity::Trace::Entity::Output.new(
|
21
|
-
wrap_config[:task], {}, wrap_config[:return_signal]
|
22
|
-
).freeze
|
23
|
-
|
24
|
-
original_flow_options[:stack].unindent!
|
25
|
-
|
26
|
-
|
27
|
-
return Trailblazer::Activity::Right, [wrap_config, original_args], circuit_options
|
28
|
-
end
|
29
|
-
|
30
|
-
# It's important to understand that {flow[:stack]} is mutated by design. This is needed so
|
31
|
-
# in case of exceptions we still have a "global" trace - unfortunately Ruby doesn't allow
|
32
|
-
# us a better way.
|
33
|
-
def capture_for(task, (ctx, flow), activity:, **circuit_options)
|
34
|
-
flow[:stack].indent!
|
35
|
-
|
36
|
-
flow[:stack] << Trailblazer::Activity::Trace::Entity::Input.new(
|
37
|
-
task, activity
|
38
|
-
).freeze
|
39
|
-
|
40
|
-
return [ctx, flow], circuit_options.merge(activity: activity)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
data/lib/trailblazer/circuit.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
module Trailblazer
|
2
|
-
# Running a Circuit instance will run all tasks sequentially depending on the former's result.
|
3
|
-
# Each task is called and retrieves the former task's return values.
|
4
|
-
#
|
5
|
-
# Note: Please use #Activity as a public circuit builder.
|
6
|
-
#
|
7
|
-
# @param map [Hash] Defines the wiring.
|
8
|
-
# @param stop_events [Array] Tasks that stop execution of the circuit.
|
9
|
-
#
|
10
|
-
# result = circuit.(start_at, *args)
|
11
|
-
#
|
12
|
-
# @see Activity
|
13
|
-
# @api semi-private
|
14
|
-
#
|
15
|
-
# This is the "pipeline operator"'s implementation.
|
16
|
-
class Circuit
|
17
|
-
def initialize(map, stop_events, start_task:, name: nil)
|
18
|
-
@map = map
|
19
|
-
@stop_events = stop_events
|
20
|
-
@name = name
|
21
|
-
@start_task = start_task
|
22
|
-
end
|
23
|
-
|
24
|
-
# @param args [Array] all arguments to be passed to the task's `call`
|
25
|
-
# @param task [callable] task to call
|
26
|
-
Run = ->(task, args, **circuit_options) { task.(args, **circuit_options) }
|
27
|
-
|
28
|
-
# Runs the circuit until we hit a stop event.
|
29
|
-
#
|
30
|
-
# This method throws exceptions when the returned value of a task doesn't match
|
31
|
-
# any wiring.
|
32
|
-
#
|
33
|
-
# @param task An event or task of this circuit from where to start
|
34
|
-
# @param options anything you want to pass to the first task
|
35
|
-
# @param flow_options Library-specific flow control data
|
36
|
-
# @return [last_signal, options, flow_options, *args]
|
37
|
-
#
|
38
|
-
# NOTE: returned circuit_options are discarded when calling the runner.
|
39
|
-
def call(args, start_task: @start_task, runner: Run, **circuit_options)
|
40
|
-
circuit_options = circuit_options.merge( runner: runner ).freeze # TODO: set the :runner option via arguments_for_call to save the merge?
|
41
|
-
task = start_task
|
42
|
-
|
43
|
-
loop do
|
44
|
-
last_signal, args, _discarded_circuit_options = runner.(
|
45
|
-
task,
|
46
|
-
args,
|
47
|
-
circuit_options
|
48
|
-
)
|
49
|
-
|
50
|
-
# Stop execution of the circuit when we hit a stop event (< End). This could be an task's End or Suspend.
|
51
|
-
return [ last_signal, args ] if @stop_events.include?(task) # DISCUSS: return circuit_options here?
|
52
|
-
|
53
|
-
task = next_for(task, last_signal) or raise IllegalSignalError.new("<#{@name}>[#{task}][ #{last_signal.inspect} ]")
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# Returns the circuit's components.
|
58
|
-
def to_h
|
59
|
-
{ map: @map, end_events: @stop_events, start_task: @start_task }
|
60
|
-
end
|
61
|
-
|
62
|
-
private
|
63
|
-
def next_for(last_task, signal)
|
64
|
-
outputs = @map[last_task]
|
65
|
-
outputs[signal]
|
66
|
-
end
|
67
|
-
|
68
|
-
class IllegalSignalError < RuntimeError
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|