trailblazer-circuit 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/lib/trailblazer/circuit/activity.rb +4 -5
- data/lib/trailblazer/circuit/version.rb +1 -1
- data/lib/trailblazer/circuit.rb +17 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 760ef971087c4983eb7d4f624bca5d78130be9b2
|
4
|
+
data.tar.gz: f763cd9f2193d16440514a183cb0935955d2158a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d6ae7c2daa02a06ae5db0846cb78068cb09b8d489ff2ec5b8ad5d3e2308e055051cb4b0e9d25be64c2709650619f434d78b910852d8d046631a8fa4af94002f
|
7
|
+
data.tar.gz: b306b440d01b1aa11c3faf587ef7970603dc58b95a3c4636eda3a76bad486c32c363db8a2ca449fd069396dbf12d8a2c052267a4cbadeaa0380ce4ac19075493
|
data/CHANGES.md
CHANGED
@@ -34,15 +34,14 @@ module Trailblazer
|
|
34
34
|
Circuit.new(yield(events), end_events, name)
|
35
35
|
end
|
36
36
|
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
# :private:
|
37
|
+
# @data structure to hold events for an activity, keyed by type, then name.
|
38
|
+
# @api private
|
41
39
|
def self.Events(events)
|
42
40
|
evts = Struct.new(*events.keys) do # [Start, End, Resume]
|
43
41
|
def [](event, name=:default)
|
44
42
|
cfg = super(event.downcase)
|
45
|
-
cfg[name] or raise "[Circuit] Event `#{event}.#{name} unknown."
|
43
|
+
cfg[name.to_sym] or raise "[Circuit] Event `#{event}.#{name} unknown."
|
44
|
+
# DISCUSS: the event type's events should also be a Struct to avoid :symbol vs. string.
|
46
45
|
end
|
47
46
|
end
|
48
47
|
|
data/lib/trailblazer/circuit.rb
CHANGED
@@ -2,9 +2,18 @@ require "trailblazer/circuit/version"
|
|
2
2
|
|
3
3
|
module Trailblazer
|
4
4
|
# Running a Circuit instance will run all tasks sequentially depending on the former's result.
|
5
|
-
# Each task is called and retrieves the former task's return
|
5
|
+
# Each task is called and retrieves the former task's return values.
|
6
|
+
#
|
7
|
+
# Note: Please use #Activity as a public circuit builder.
|
8
|
+
#
|
9
|
+
# @param map [Hash] Defines the wiring.
|
10
|
+
# @param stop_events [Array] Tasks that stop execution of the circuit.
|
11
|
+
# @param name [Hash] Names for tracing, debugging and exceptions. `:id` is a reserved key for circuit name.
|
6
12
|
#
|
7
13
|
# result = circuit.(start_at, *args)
|
14
|
+
#
|
15
|
+
# @see Activity
|
16
|
+
# @api semi-private
|
8
17
|
class Circuit
|
9
18
|
def initialize(map, stop_events, name)
|
10
19
|
@name = name
|
@@ -17,22 +26,24 @@ module Trailblazer
|
|
17
26
|
# Runs the circuit. Stops when hitting a End event or subclass thereof.
|
18
27
|
# This method throws exceptions when the return value of a task doesn't match
|
19
28
|
# any wiring.
|
29
|
+
#
|
20
30
|
# @param activity A task from the circuit where to start
|
21
31
|
# @param args An array of options passed to the first task.
|
22
|
-
def call(activity, args, runner: Run, **
|
32
|
+
def call(activity, args, runner: Run, **flow_options)
|
23
33
|
# TODO: args
|
24
34
|
direction = nil
|
25
|
-
flow_options = { runner: runner, debug: @name }.merge(
|
35
|
+
flow_options = { runner: runner, debug: @name }.merge(flow_options) # DISCUSS: make this better?
|
26
36
|
|
27
37
|
loop do
|
28
38
|
direction, args, flow_options = runner.( activity, direction, args, flow_options )
|
29
39
|
|
30
|
-
# Stop execution of the circuit when we hit a stop event (< End). This could be an activity's End
|
40
|
+
# Stop execution of the circuit when we hit a stop event (< End). This could be an activity's End or Suspend.
|
31
41
|
return [ direction, args, flow_options ] if @stop_events.include?(activity)
|
32
42
|
|
33
43
|
activity = next_for(activity, direction) do |next_activity, in_map|
|
34
|
-
|
35
|
-
raise
|
44
|
+
activity_name = @name[activity] || activity # TODO: this must be implemented only once, somewhere.
|
45
|
+
raise IllegalInputError.new("#{@name[:id]} #{activity_name}") unless in_map
|
46
|
+
raise IllegalOutputSignalError.new("from #{@name[:id]}: `#{activity_name}`===>[ #{direction.inspect} ]") unless next_activity
|
36
47
|
end
|
37
48
|
end
|
38
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trailblazer-circuit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|