trailblazer-operation 0.1.1 → 0.1.2
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/Gemfile +1 -1
- data/lib/trailblazer/operation.rb +7 -1
- data/lib/trailblazer/operation/railway/macaroni.rb +21 -0
- data/lib/trailblazer/operation/railway/normalizer.rb +11 -7
- data/lib/trailblazer/operation/railway/task_builder.rb +20 -26
- data/lib/trailblazer/operation/version.rb +1 -1
- data/test/docs/macaroni_test.rb +26 -0
- data/trailblazer-operation.gemspec +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d1a238c8c4bb3a49a8adad7d2ffc709f1f4766d
|
4
|
+
data.tar.gz: d3495a92e3fc1519b7e847ccd8f1ad2ff84d41a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f922d3d9a2ebbe3abdc6eb919cf6c99dbd66ffa990f041ba9a1aea6de1a2c56c5f1c436388978c434017213d6eb370059a03846613a3704a1617615d2168435
|
7
|
+
data.tar.gz: 60eabb5de8f611edc69a9c81003dc78a29c4734ba316e4cdcc6497ba7075ff4c7d1a732dca8660af1c9a327e582bb4c27ccc494820f5495c1b2b93a5fe8022a8
|
data/CHANGES.md
CHANGED
data/Gemfile
CHANGED
@@ -20,5 +20,5 @@ gem "trailblazer-developer", git: "https://github.com/trailblazer/trailblazer-de
|
|
20
20
|
|
21
21
|
# gem "declarative", path: "../declarative"
|
22
22
|
|
23
|
-
gem "trailblazer-activity", path: "../circuit"
|
23
|
+
# gem "trailblazer-activity", path: "../circuit"
|
24
24
|
# gem "trailblazer-activity", git: "https://github.com/trailblazer/trailblazer-activity"
|
@@ -50,7 +50,7 @@ module Trailblazer
|
|
50
50
|
fail_fast_end: Railway::End::FailFast.new(:fail_fast, semantic: :fail_fast),
|
51
51
|
}
|
52
52
|
|
53
|
-
@builder, @adds = Activity::Magnetic::Builder::FastTrack.for(
|
53
|
+
@builder, @adds = Activity::Magnetic::Builder::FastTrack.for( build_normalizer.freeze, builder_options )
|
54
54
|
@debug = {}
|
55
55
|
end
|
56
56
|
|
@@ -68,6 +68,12 @@ module Trailblazer
|
|
68
68
|
def __call__(args, circuit_options={})
|
69
69
|
@process.( args, circuit_options.merge( exec_context: new ) )
|
70
70
|
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def build_normalizer
|
75
|
+
Railway::Normalizer.new
|
76
|
+
end
|
71
77
|
end
|
72
78
|
|
73
79
|
extend Process # make ::call etc. class methods on Operation.
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Trailblazer
|
2
|
+
module Operation::Railway
|
3
|
+
# Call the user's steps with a differing API (inspired by Maciej Mensfeld) that
|
4
|
+
# only receives keyword args. The `options` keyword is the stateful context object
|
5
|
+
#
|
6
|
+
# def my_step( params:, ** )
|
7
|
+
# def my_step( params:, options:, ** )
|
8
|
+
module Macaroni
|
9
|
+
def self.call(user_proc)
|
10
|
+
Task.new( Trailblazer::Option.build( Macaroni::Option, user_proc ), user_proc )
|
11
|
+
end
|
12
|
+
|
13
|
+
class Option < Trailblazer::Option
|
14
|
+
# The Option#call! method prepares the arguments.
|
15
|
+
def self.call!(proc, options, *)
|
16
|
+
proc.( **options.to_hash.merge( options: options ) )
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -5,8 +5,12 @@ module Trailblazer
|
|
5
5
|
# task via {TaskBuilder} in order to translate true/false to `Right` or `Left`.
|
6
6
|
#
|
7
7
|
# The Normalizer sits in the `@builder`, which receives all DSL calls from the Operation subclass.
|
8
|
-
|
9
|
-
def
|
8
|
+
class Normalizer
|
9
|
+
def initialize(task_builder: TaskBuilder, **options)
|
10
|
+
@task_builder = task_builder
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(task, options, unknown_options, sequence_options)
|
10
14
|
wrapped_task, options =
|
11
15
|
if task.is_a?(::Hash) # macro.
|
12
16
|
[
|
@@ -17,7 +21,7 @@ module Trailblazer
|
|
17
21
|
Operation::DeprecatedMacro.( *task )
|
18
22
|
else # user step
|
19
23
|
[
|
20
|
-
|
24
|
+
@task_builder.(task),
|
21
25
|
{ id: task }.merge(options) # default :id
|
22
26
|
]
|
23
27
|
end
|
@@ -35,28 +39,28 @@ module Trailblazer
|
|
35
39
|
end
|
36
40
|
|
37
41
|
# Merge user options over defaults.
|
38
|
-
def
|
42
|
+
def defaultize(task, options)
|
39
43
|
{
|
40
44
|
plus_poles: InitialPlusPoles(),
|
41
45
|
}.merge(options)
|
42
46
|
end
|
43
47
|
|
44
48
|
# Handle the :override option which is specific to Operation.
|
45
|
-
def
|
49
|
+
def override(task, options, sequence_options)
|
46
50
|
options, locals = Activity::Magnetic::Builder.normalize(options, [:override])
|
47
51
|
sequence_options = sequence_options.merge( replace: options[:id] ) if locals[:override]
|
48
52
|
|
49
53
|
return options, locals, sequence_options
|
50
54
|
end
|
51
55
|
|
52
|
-
def
|
56
|
+
def InitialPlusPoles
|
53
57
|
Activity::Magnetic::DSL::PlusPoles.new.merge(
|
54
58
|
Activity.Output(Activity::Right, :success) => nil,
|
55
59
|
Activity.Output(Activity::Left, :failure) => nil,
|
56
60
|
)
|
57
61
|
end
|
58
62
|
|
59
|
-
def
|
63
|
+
def deprecate_name(options, unknown_options) # TODO remove in 2.2
|
60
64
|
unknown_options, deprecated_options = Activity::Magnetic::Builder.normalize(unknown_options, [:name])
|
61
65
|
|
62
66
|
options = options.merge( name: deprecated_options[:name] ) if deprecated_options[:name]
|
@@ -5,39 +5,33 @@ module Trailblazer
|
|
5
5
|
# Output direction binary: true=>Right, false=>Left.
|
6
6
|
# Passes through all subclasses of Direction.~~~~~~~~~~~~~~~~~
|
7
7
|
module TaskBuilder
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
super &block
|
12
|
-
end
|
13
|
-
|
14
|
-
def to_s
|
15
|
-
"<Railway::Task{#{@source_location}}>"
|
16
|
-
end
|
8
|
+
def self.call(user_proc)
|
9
|
+
Task.new( Trailblazer::Option::KW( user_proc ), user_proc )
|
10
|
+
end
|
17
11
|
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
# Translates the return value of the user step into a valid signal.
|
13
|
+
# Note that it passes through subclasses of {Signal}.
|
14
|
+
def self.binary_direction_for(result, on_true, on_false)
|
15
|
+
result.is_a?(Class) && result < Activity::Signal ? result : (result ? on_true : on_false)
|
21
16
|
end
|
17
|
+
end
|
22
18
|
|
23
|
-
|
19
|
+
class Task
|
20
|
+
def initialize(task, user_proc)
|
21
|
+
@task = task
|
22
|
+
@user_proc = user_proc
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
# Execute the user step with TRB's kw args.
|
28
|
-
result = Trailblazer::Option::KW(step).(options, **circuit_args) # circuit_args contains :exec_context.
|
24
|
+
freeze
|
25
|
+
end
|
29
26
|
|
30
|
-
|
31
|
-
|
27
|
+
def call( (options, *args), **circuit_args )
|
28
|
+
# Execute the user step with TRB's kw args.
|
29
|
+
result = @task.( options, **circuit_args ) # circuit_args contains :exec_context.
|
32
30
|
|
33
|
-
|
34
|
-
|
35
|
-
end
|
31
|
+
# Return an appropriate signal which direction to go next.
|
32
|
+
direction = TaskBuilder.binary_direction_for( result, Activity::Right, Activity::Left )
|
36
33
|
|
37
|
-
|
38
|
-
# Note that it passes through subclasses of {Signal}.
|
39
|
-
def self.binary_direction_for(result, on_true, on_false)
|
40
|
-
result.is_a?(Class) && result < Activity::Signal ? result : (result ? on_true : on_false)
|
34
|
+
[ direction, [ options, *args ], **circuit_args ]
|
41
35
|
end
|
42
36
|
end
|
43
37
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
require "trailblazer/operation/railway/macaroni"
|
4
|
+
|
5
|
+
class MacaroniTaskBuilderTest < Minitest::Spec
|
6
|
+
module Memo; end
|
7
|
+
|
8
|
+
class Memo::Create < Trailblazer::Operation
|
9
|
+
Normalizer = Railway::Normalizer.new( task_builder: Railway::Macaroni )
|
10
|
+
|
11
|
+
step :create_model, normalizer: Normalizer
|
12
|
+
step :save, normalizer: Normalizer
|
13
|
+
|
14
|
+
def create_model(params:, options:, **)
|
15
|
+
options[:model] = params[:title]
|
16
|
+
end
|
17
|
+
|
18
|
+
def save(model:, **)
|
19
|
+
model.reverse!
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "allows optional macaroni call style" do
|
24
|
+
Memo::Create.( params: { title: "Wow!" } ).inspect(:model).must_equal %{<Result:true ["!woW"] >}
|
25
|
+
end
|
26
|
+
end
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_dependency "trailblazer-activity", ">= 0.3.
|
20
|
+
spec.add_dependency "trailblazer-activity", ">= 0.3.1", "< 0.4.0"
|
21
21
|
spec.add_dependency "trailblazer-context", ">= 0.1.1", "< 0.3.0"
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trailblazer-operation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.3.
|
19
|
+
version: 0.3.1
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 0.4.0
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.3.
|
29
|
+
version: 0.3.1
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 0.4.0
|
@@ -112,6 +112,7 @@ files:
|
|
112
112
|
- lib/trailblazer/operation/public_call.rb
|
113
113
|
- lib/trailblazer/operation/railway.rb
|
114
114
|
- lib/trailblazer/operation/railway/fast_track.rb
|
115
|
+
- lib/trailblazer/operation/railway/macaroni.rb
|
115
116
|
- lib/trailblazer/operation/railway/normalizer.rb
|
116
117
|
- lib/trailblazer/operation/railway/task_builder.rb
|
117
118
|
- lib/trailblazer/operation/result.rb
|
@@ -124,6 +125,7 @@ files:
|
|
124
125
|
- test/call_test.rb
|
125
126
|
- test/class_dependencies_test.rb
|
126
127
|
- test/docs/doormat_test.rb
|
128
|
+
- test/docs/macaroni_test.rb
|
127
129
|
- test/docs/wiring_test.rb
|
128
130
|
- test/dry_container_test.rb
|
129
131
|
- test/fast_track_test.rb
|
@@ -178,6 +180,7 @@ test_files:
|
|
178
180
|
- test/call_test.rb
|
179
181
|
- test/class_dependencies_test.rb
|
180
182
|
- test/docs/doormat_test.rb
|
183
|
+
- test/docs/macaroni_test.rb
|
181
184
|
- test/docs/wiring_test.rb
|
182
185
|
- test/dry_container_test.rb
|
183
186
|
- test/fast_track_test.rb
|