trailblazer-circuit 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72877a8ce955ec1dc23b9f100bda0974e1bcd40f
4
- data.tar.gz: c71ca90a053245f55c75573bea74584b2056f14c
3
+ metadata.gz: 760ef971087c4983eb7d4f624bca5d78130be9b2
4
+ data.tar.gz: f763cd9f2193d16440514a183cb0935955d2158a
5
5
  SHA512:
6
- metadata.gz: 4f8fa59da9c333fefdf5c5b37a273d520bbfc346c4d2d80a1455447b7bd85e878a523112e58e4a231ac220969b33e12428902c4fe8ab9155a615c0c093ade6a3
7
- data.tar.gz: e4aef9035fe3a68b81fda3f178e6e37ac9fb9f04fe20b64e5de4cdd850e04b2214d398b9b1439c7d568634a43709ced757f7201174abce5a8fddae74f645fb19
6
+ metadata.gz: 8d6ae7c2daa02a06ae5db0846cb78068cb09b8d489ff2ec5b8ad5d3e2308e055051cb4b0e9d25be64c2709650619f434d78b910852d8d046631a8fa4af94002f
7
+ data.tar.gz: b306b440d01b1aa11c3faf587ef7970603dc58b95a3c4636eda3a76bad486c32c363db8a2ca449fd069396dbf12d8a2c052267a4cbadeaa0380ce4ac19075493
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.0.3
2
+
3
+ * Make the first argument to `#Activity` (`@name`) always a Hash where `:id` is a reserved key for the name of the circuit.
4
+
1
5
  # 0.0.2
2
6
 
3
7
  * Make `flow_options` an immutable data structure just as `options`. It now needs to be returned from a `#call`.
@@ -34,15 +34,14 @@ module Trailblazer
34
34
  Circuit.new(yield(events), end_events, name)
35
35
  end
36
36
 
37
- # DSL
38
- # events[:Start]
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
 
@@ -1,5 +1,5 @@
1
1
  module Trailblazer
2
2
  class Circuit
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -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 value.
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, **o)
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(o) # DISCUSS: make this better?
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 of Suspend.
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
- raise IllegalInputError.new("#{@name} #{activity}") unless in_map
35
- raise IllegalOutputSignalError.new("from #{@name};;#{activity}"+ direction.inspect) unless next_activity
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.2
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-02 00:00:00.000000000 Z
11
+ date: 2017-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler