trailblazer-activity-dsl-linear 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6c778b5c85e44e0bada5fd6b073bca7c5ad859dd7e7670970ded5828253f12f
4
- data.tar.gz: 016efb08c0817d3075ec0d504ceaf00a79cd69021b0db2a3b00445592a04e6b9
3
+ metadata.gz: f2dd213289e88821986b93fc8421474654537f47cee570eb1d3b14e8a6b22020
4
+ data.tar.gz: 8e64b5daeec8cf1781c4e0411b9bba9a482bdd66a52509281996615ec55eb708
5
5
  SHA512:
6
- metadata.gz: 6a4781c4a6edb5d16078cd48be9379d862be9d13c6f62ba849b86fe872c33411541456bba91ed64ae96125b9526053976a77910ddcaae68e92227391378a7d83
7
- data.tar.gz: 9bcd652ff1be61710625ab18fb20af9e765f49be8f02e940b6b3ebab2a43e679fb0299a9faa354501229c6f411fd76a3698db4ea29404ae15baf9b5693eb338e
6
+ metadata.gz: 3a8bece3d93808c8267f18200dbb55556f8916d6f0071a5d53f33a462fc34c0d9084c0a1d4ffcef084f459bf738e08b7f358ff189d4e86f3abd716aaa688f611
7
+ data.tar.gz: d6758434610eeb29d00f31744e250b26d4258364d17aaefaf6ea8e3355040a27b7b8adc453514272d076e53aeb313ec7af56573ff57b99e136e6b8941a7bde3a
data/CHANGES.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.2.8
2
+
3
+ * Add `Track(:color, wrap_around: true)` option and `Search::WrapAround` so you can find a certain track color (or the beginning of a Path) even when the path was positioned before the actual step in the `Sequence`.
4
+ * Add `:inherit` option so `step` can override an existing step while inheriting the original `:extensions` and `:connections` (which are the `Outputs`). This is great to customize "template" activities.
5
+
1
6
  # 0.2.7
2
7
 
3
8
  * `Did you mean ?` suggestions on Linear::Sequence::IndexError.
data/Gemfile CHANGED
@@ -10,3 +10,4 @@ gem "rubocop", require: false
10
10
  # gem "trailblazer-context", path: "../trailblazer-context"
11
11
  # gem "trailblazer-developer", path: "../trailblazer-developer"
12
12
  # gem "trailblazer-activity", path: "../trailblazer-activity"
13
+ # gem "trailblazer-activity", path: "../circuit"
@@ -58,7 +58,21 @@ class Trailblazer::Activity
58
58
  # Note that we only go forward, no back-references are done here.
59
59
  def Forward(output, target_color)
60
60
  ->(sequence, me) do
61
- target_seq_row = sequence[sequence.index(me)+1..-1].find { |seq_row| seq_row[0] == target_color }
61
+ target_seq_row = find_in_range(sequence[sequence.index(me)+1..-1], target_color)
62
+
63
+ return output, target_seq_row
64
+ end
65
+ end
66
+
67
+ # Tries to find a track colored step by doing a Forward-search, first, then wraps around going
68
+ # through all steps from sequence start to self.
69
+ def WrapAround(output, target_color)
70
+ ->(sequence, me) do
71
+ my_index = sequence.index(me)
72
+ # First, try all elements after me, then go through the elements preceding myself.
73
+ wrapped_range = sequence[my_index+1..-1] + sequence[0..my_index-1]
74
+
75
+ target_seq_row = find_in_range(wrapped_range, target_color)
62
76
 
63
77
  return output, target_seq_row
64
78
  end
@@ -79,6 +93,11 @@ class Trailblazer::Activity
79
93
  return output, target_seq_row
80
94
  end
81
95
  end
96
+
97
+ # @private
98
+ def find_in_range(range, target_color)
99
+ target_seq_row = range.find { |seq_row| seq_row[0] == target_color }
100
+ end
82
101
  end # Search
83
102
 
84
103
  # Sequence
@@ -6,7 +6,7 @@ module Trailblazer
6
6
  # @api private
7
7
  OutputSemantic = Struct.new(:value)
8
8
  Id = Struct.new(:value)
9
- Track = Struct.new(:color, :adds)
9
+ Track = Struct.new(:color, :adds, :options)
10
10
  Extension = Struct.new(:callable) do
11
11
  def call(*args, &block)
12
12
  callable.(*args, &block)
@@ -35,8 +35,8 @@ module Trailblazer
35
35
  "End.#{_end.to_h[:semantic]}" # TODO: use everywhere
36
36
  end
37
37
 
38
- def Track(color)
39
- Track.new(color, []).freeze
38
+ def Track(color, wrap_around: false)
39
+ Track.new(color, [], wrap_around: wrap_around).freeze
40
40
  end
41
41
 
42
42
  def Id(id)
@@ -81,7 +81,7 @@ module Trailblazer
81
81
  end
82
82
 
83
83
  # Connect the Output() => Track(path_track)
84
- return Track.new(track_color, adds)
84
+ return Track.new(track_color, adds, {})
85
85
  end
86
86
 
87
87
  # Computes the {:outputs} options for {activity}.
@@ -20,6 +20,7 @@ module Trailblazer
20
20
  "activity.normalize_id" => method(:normalize_id),
21
21
  "activity.normalize_override" => method(:normalize_override),
22
22
  "activity.wrap_task_with_step_interface" => method(:wrap_task_with_step_interface), # last
23
+ "activity.inherit_option" => method(:inherit_option),
23
24
  },
24
25
 
25
26
  Linear::Insert.method(:Append), "Start.default"
@@ -128,7 +129,7 @@ module Trailblazer
128
129
 
129
130
  ctx[:wirings] =
130
131
  connections.collect do |semantic, (search_strategy_builder, *search_args)|
131
- output = outputs[semantic] || raise("No `#{semantic}` output found for #{outputs.inspect}")
132
+ output = outputs[semantic] || raise("No `#{semantic}` output found for #{ctx[:id].inspect} and outputs #{outputs.inspect}")
132
133
 
133
134
  search_strategy_builder.( # return proc to be called when compiling Seq, e.g. {ById(output, :id)}
134
135
  output,
@@ -176,8 +177,10 @@ module Trailblazer
176
177
  return Trailblazer::Activity::Right, [new_ctx, flow_options]
177
178
  end
178
179
 
179
- def output_to_track(ctx, output, target)
180
- {output.value => [Linear::Search.method(:Forward), target.color]}
180
+ def output_to_track(ctx, output, track)
181
+ search_strategy = track.options[:wrap_around] ? :WrapAround : :Forward
182
+
183
+ {output.value => [Linear::Search.method(search_strategy), track.color]}
181
184
  end
182
185
 
183
186
  def output_to_id(ctx, output, target)
@@ -227,9 +230,28 @@ module Trailblazer
227
230
  return Trailblazer::Activity::Right, [ctx.merge(new_ctx), flow_options]
228
231
  end
229
232
 
233
+ # Currently, the {:inherit} option copies over {:connections} from the original step
234
+ # and merges them with the (prolly) connections passed from the user.
235
+ def inherit_option((ctx, flow_options), *)
236
+ return Trailblazer::Activity::Right, [ctx, flow_options] unless ctx[:inherit]
237
+
238
+ sequence = ctx[:sequence]
239
+ id = ctx[:id]
240
+
241
+ index = Linear::Insert.find_index(sequence, id)
242
+ row = sequence[index] # from this row we're inheriting options.
243
+
244
+ extensions = (row[3][:extensions]||[]) + (ctx[:extensions]||[]) # FIXME: DEFAULTING, FOR FUCK'S SAKE
245
+
246
+ ctx = ctx.merge(connections: row[3][:connections], extensions: extensions) # "inherit"
247
+
248
+ return Trailblazer::Activity::Right, [ctx, flow_options]
249
+ end
250
+
230
251
  # TODO: make this extendable!
231
252
  def cleanup_options((ctx, flow_options), *)
232
- new_ctx = ctx.reject { |k, v| [:connections, :outputs, :end_id, :step_interface_builder, :failure_end, :track_name, :sequence].include?(k) }
253
+ # new_ctx = ctx.reject { |k, v| [:connections, :outputs, :end_id, :step_interface_builder, :failure_end, :track_name, :sequence].include?(k) }
254
+ new_ctx = ctx.reject { |k, v| [:outputs, :end_id, :step_interface_builder, :failure_end, :track_name, :sequence].include?(k) }
233
255
 
234
256
  return Trailblazer::Activity::Right, [new_ctx, flow_options]
235
257
  end
@@ -3,7 +3,7 @@ module Trailblazer
3
3
  module Activity
4
4
  module DSL
5
5
  module Linear
6
- VERSION = "0.2.7"
6
+ VERSION = "0.2.8"
7
7
  end
8
8
  end
9
9
  end
@@ -90,6 +90,8 @@ module Trailblazer
90
90
  )
91
91
  end
92
92
 
93
+ # Add {:failure} output to {:outputs}.
94
+ # TODO: assert that failure_outputs doesn't override existing {:outputs}
93
95
  def normalize_path_outputs((ctx, flow_options), *)
94
96
  outputs = failure_outputs.merge(ctx[:outputs])
95
97
  ctx = ctx.merge(outputs: outputs)
@@ -132,7 +134,6 @@ module Trailblazer
132
134
  pass: Linear::Normalizer.activity_normalizer( Railway::DSL.normalizer_for_pass ),
133
135
  )
134
136
 
135
-
136
137
  def self.OptionsForState(normalizers: Normalizers, failure_end: Activity::End.new(semantic: :failure), **options)
137
138
  options = Path::DSL.OptionsForState(options).
138
139
  merge(normalizers: normalizers, failure_end: failure_end)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailblazer-activity-dsl-linear
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-22 00:00:00.000000000 Z
11
+ date: 2020-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trailblazer-activity
@@ -135,7 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  - !ruby/object:Gem::Version
136
136
  version: '0'
137
137
  requirements: []
138
- rubygems_version: 3.0.8
138
+ rubyforge_project:
139
+ rubygems_version: 2.7.6
139
140
  signing_key:
140
141
  specification_version: 4
141
142
  summary: Simple DSL to define Trailblazer activities.