trailblazer-activity-dsl-linear 0.2.5 → 0.2.6

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
  SHA256:
3
- metadata.gz: d7b19b59ebf1ee26717edb3a9d5e797eec4a4796bc567bdc21ee92ba13fd4a04
4
- data.tar.gz: 782a283ddf31bdebc6575323c7fcdae0958f301802793c5d193b2c42494f1076
3
+ metadata.gz: 74aa92e841b1cec015946ecabf0a7dde756df34adf30820db522223be3452870
4
+ data.tar.gz: 438194ab7ef0f1ad3f17a63e6306d426ae8e8a3544f33e78bb9e8292af7c7408
5
5
  SHA512:
6
- metadata.gz: bc097663260f945545c68f4f7f9c8e6023631b5ff67552ec0baf0ee39acdf3b6c8517c31b31aecadcaf8d61b09e04ee31c033d0ae80b5019f5cc0b3392da64b1
7
- data.tar.gz: cafc5c1e5dd50768986066988efac3b4fcbc37a5da13e10b2ca542fec63eb7193dee59a6379437bdd3ac69ea3a2e492065c4c076755e58432b11461e215fb01b
6
+ metadata.gz: 946cddafc751a2b2c9c385911080871a3f7b43231814cf2b351728cc0ae9eaf1297e30e1ed604d6d150ce4c5add9fc74820660e53a61e9b9528691ae805c15d4
7
+ data.tar.gz: f8218e47483f166fb9bbc3f036b86a8bde0aced4c1e34a8c3be1558d94eb54c98c7159b432d6e1c3533df5f92991cd7184cb6403806f8bb0ed8c661ffb42b42e
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.2.6
2
+
3
+ * Added `@fields` to `Linear::State` to save arbitrary data on the activity/strategy level.
4
+
1
5
  # 0.2.5
2
6
 
3
7
  * Patching now requires the [`:patch` option for `Subprocess`](http://2019.trailblazer.to/2.1/docs/activity.html#activity-dsl-options-patching
data/README.md CHANGED
@@ -1,29 +1,93 @@
1
- # Trailblazer-Activity-DSL-Linear
1
+ # Activity-DSL-Linear
2
2
 
3
- _The popular Railway/Fasttrack DSL for building activities._
3
+ The `activity-dsl-linear` gem brings:
4
+ - [Path](https://2019.trailblazer.to/2.1/docs/activity.html#activity-strategy-path)
5
+ - [Railway](https://2019.trailblazer.to/2.1/docs/activity.html#activity-strategy-railway)
6
+ - [Fasttrack](https://2019.trailblazer.to/2.1/docs/activity.html#activity-strategy-fasttrack)
7
+
8
+ DSLs strategies for buildig activities. It is build around [`activity`](https://github.com/trailblazer/trailblazer-activity) gem.
4
9
 
10
+ Please find the [full documentation on the Trailblazer website](https://2019.trailblazer.to/2.1/docs/activity.html#activity-strategy). [Note that the docs are WIP.]
5
11
 
6
- # Overview
12
+ ## Example
7
13
 
8
- This gem allows creating activities by leveraging a handy DSL. Built-in are the strategies `Path`, the popular `Railway` and `FastTrack`. The latter is used for `Trailblazer::Operation`.
14
+ The `activity-dsl-linear` gem provides three default patterns to model processes: `Path`, `Railway` and `FastTrack`. Here's an example of what a railway activity could look like, along with some more complex connections (you can read more about Railway strategy in the [docs](https://2019.trailblazer.to/2.1/docs/activity.html#activity-strategy-railway)).
9
15
 
10
- Note that you don't need to use the DSL. You can simply create a InIm structure yourself, or use our online editor.
16
+ ```ruby
17
+ require "trailblazer-activity"
18
+ require "trailblazer-activity-dsl-linear"
11
19
 
12
- Full documentation can be found here: trailblazer.to/2.1/#dsl-linear
20
+ class Memo::Update < Trailblazer::Activity::Railway
21
+ # here goes your business logic
22
+ #
23
+ def find_model(ctx, id:, **)
24
+ ctx[:model] = Memo.find_by(id: id)
25
+ end
13
26
 
14
- ## Normalizer
27
+ def validate(ctx, params:, **)
28
+ return true if params[:body].is_a?(String) && params[:body].size > 10
29
+ ctx[:errors] = "body not long enough"
30
+ false
31
+ end
15
32
 
16
- Normalizers are itself linear activities (or "pipelines") that compute all options necessary for `DSL.insert_task`.
17
- For example, `FailFast.normalizer` will process your options such as `fast_track: true` and add necessary connections and outputs.
33
+ def save(ctx, model:, params:, **)
34
+ model.update_attributes(params)
35
+ end
18
36
 
19
- The different "step types" (think of `step`, `fail`, and `pass`) are again implemented as different normalizers that "inherit" generic steps.
37
+ def log_error(ctx, params:, **)
38
+ ctx[:log] = "Some idiot wrote #{params.inspect}"
39
+ end
20
40
 
41
+ # here comes the DSL describing the layout of the activity
42
+ #
43
+ step :find_model
44
+ step :validate, Output(:failure) => End(:validation_error)
45
+ step :save
46
+ fail :log_error
47
+ end
48
+ ```
21
49
 
22
- `:sequence_insert`
23
- `:connections` are callables to find the connecting tasks
50
+ Visually, this would translate to the following circuit.
51
+
52
+ <img src="http://trailblazer.to/images/2.1/activity-readme-example.png">
53
+
54
+ You can run the activity by invoking its `call` method.
55
+
56
+ ```ruby
57
+ ctx = { id: 1, params: { body: "Awesome!" } }
58
+
59
+ signal, (ctx, *) = Update.( [ctx, {}] )
60
+
61
+ pp ctx #=>
62
+ {:id=>1,
63
+ :params=>{:body=>"Awesome!"},
64
+ :model=>#<Memo body=nil>,
65
+ :errors=>"body not long enough"}
66
+
67
+ pp signal #=> #<struct Trailblazer::Activity::End semantic=:validation_error>
68
+ ```
69
+
70
+ With Activity, modeling business processes turns out to be ridiculously simple: You define what should happen and when, and Trailblazer makes sure _that_ it happens.
71
+
72
+ ## Features
73
+
74
+ * Activities can model any process with arbitrary flow and connections.
75
+ * Nesting and compositions are allowed and encouraged (via Trailblazer's [`dsl-linear`](https://github.com/trailblazer/trailblazer-activity-dsl-linear) gem).
76
+ * Different step interfaces, manual processing of DSL options, etc is all possible.
77
+ * Steps can be any kind of callable objects.
78
+ * Tracing! (via Trailblazer's [`developer`](https://github.com/trailblazer/trailblazer-developer) gem)
79
+
80
+ ## Operation
81
+
82
+ Trailblazer's [`Operation`](https://2019.trailblazer.to/2.1/docs/operation.html#operation-overview) internally uses an activity to model the processes.
83
+
84
+ ## Workflow
85
+ Activities can be formed into bigger compounds and using workflow, you can build long-running processes such as a moderated blog post or a parcel delivery. Also, you don't have to use the DSL but can use the [`editor`](https://2019.trailblazer.to/2.1/docs/pro.html#pro-editor)instead(cool for more complex, long-running flows). Here comes a sample screenshot.
86
+
87
+ <img src="http://2019.trailblazer.to/2.1/dist/img/flow.png">
24
88
 
25
89
  ## License
26
90
 
27
91
  © Copyright 2018, Trailblazer GmbH
28
92
 
29
- Licensed under the LGPLv3 license. We also offer a [commercial-friendly license](http://trailblazer.to/pro).
93
+ Licensed under the LGPLv3 license. We also offer a commercial-friendly [license](https://2019.trailblazer.to/2.1/docs/pro.html#pro-license).
@@ -3,28 +3,40 @@ module Trailblazer
3
3
  module DSL
4
4
  module Linear
5
5
  # A {State} instance is kept per DSL client, which usually is a subclass of {Path}, {Railway}, etc.
6
+ # State doesn't have any immutable features - all write operations to it must guarantee they only replace
7
+ # instance variables.
8
+ #
9
+ # @private
10
+ #
11
+ # DISCUSS: why do we have this structure? It doesn't cover "immutable copying", that has to be done by its clients.
12
+ # also, copy with to_h
6
13
  class State
7
14
  # remembers how to call normalizers (e.g. track_color), TaskBuilder
8
15
  # remembers sequence
9
- def initialize(normalizers:, initial_sequence:, **normalizer_options)
16
+ def initialize(normalizers:, initial_sequence:, fields: {}.freeze, **normalizer_options)
10
17
  @normalizer = normalizers # compiled normalizers.
11
18
  @sequence = initial_sequence
12
19
  @normalizer_options = normalizer_options
20
+ @fields = fields
13
21
  end
14
22
 
15
23
  # Called to "inherit" a state.
16
24
  def copy
17
- self.class.new(normalizers: @normalizer, initial_sequence: @sequence, **@normalizer_options)
25
+ self.class.new(normalizers: @normalizer, initial_sequence: @sequence, fields: @fields, **@normalizer_options)
18
26
  end
19
27
 
20
28
  def to_h
21
- {sequence: @sequence, normalizers: @normalizer, normalizer_options: @normalizer_options} # FIXME.
29
+ {sequence: @sequence, normalizers: @normalizer, normalizer_options: @normalizer_options, fields: @fields} # FIXME.
22
30
  end
23
31
 
24
32
  def update_sequence(&block)
25
33
  @sequence = yield(to_h)
26
34
  end
27
35
 
36
+ def update_options(fields)
37
+ @fields = fields
38
+ end
39
+
28
40
  # Compiles and maintains all final normalizers for a specific DSL.
29
41
  class Normalizer
30
42
  def compile_normalizer(normalizer_sequence)
@@ -29,7 +29,7 @@ module Trailblazer
29
29
  options = options.merge(dsl_track: type)
30
30
 
31
31
  # {#update_sequence} is the only way to mutate the state instance.
32
- state.update_sequence do |sequence:, normalizers:, normalizer_options:|
32
+ state.update_sequence do |sequence:, normalizers:, normalizer_options:, fields:|
33
33
  # Compute the sequence rows.
34
34
  options = normalizers.(type, normalizer_options: normalizer_options, options: task, user_options: options.merge(sequence: sequence))
35
35
 
@@ -3,7 +3,7 @@ module Trailblazer
3
3
  module Activity
4
4
  module DSL
5
5
  module Linear
6
- VERSION = "0.2.5"
6
+ VERSION = "0.2.6"
7
7
  end
8
8
  end
9
9
  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.5
4
+ version: 0.2.6
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-01-08 00:00:00.000000000 Z
11
+ date: 2020-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trailblazer-activity