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 +4 -4
- data/CHANGES.md +4 -0
- data/README.md +77 -13
- data/lib/trailblazer/activity/dsl/linear/state.rb +15 -3
- data/lib/trailblazer/activity/dsl/linear/strategy.rb +1 -1
- data/lib/trailblazer/activity/dsl/linear/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74aa92e841b1cec015946ecabf0a7dde756df34adf30820db522223be3452870
|
4
|
+
data.tar.gz: 438194ab7ef0f1ad3f17a63e6306d426ae8e8a3544f33e78bb9e8292af7c7408
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 946cddafc751a2b2c9c385911080871a3f7b43231814cf2b351728cc0ae9eaf1297e30e1ed604d6d150ce4c5add9fc74820660e53a61e9b9528691ae805c15d4
|
7
|
+
data.tar.gz: f8218e47483f166fb9bbc3f036b86a8bde0aced4c1e34a8c3be1558d94eb54c98c7159b432d6e1c3533df5f92991cd7184cb6403806f8bb0ed8c661ffb42b42e
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -1,29 +1,93 @@
|
|
1
|
-
#
|
1
|
+
# Activity-DSL-Linear
|
2
2
|
|
3
|
-
|
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
|
-
|
12
|
+
## Example
|
7
13
|
|
8
|
-
|
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
|
-
|
16
|
+
```ruby
|
17
|
+
require "trailblazer-activity"
|
18
|
+
require "trailblazer-activity-dsl-linear"
|
11
19
|
|
12
|
-
|
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
|
-
|
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
|
-
|
17
|
-
|
33
|
+
def save(ctx, model:, params:, **)
|
34
|
+
model.update_attributes(params)
|
35
|
+
end
|
18
36
|
|
19
|
-
|
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
|
-
|
23
|
-
|
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
|
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
|
|
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.
|
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-
|
11
|
+
date: 2020-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trailblazer-activity
|