trailblazer 2.1.0.beta1 → 2.1.0.beta2

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.
@@ -3,7 +3,7 @@ class Trailblazer::Operation
3
3
  # false is automatically connected to End.failure.
4
4
 
5
5
  def self.Wrap(user_wrap, id: "Wrap/#{rand(100)}", &block)
6
- operation_class = Wrap.Operation(block)
6
+ operation_class = Wrap.create_operation(block)
7
7
  wrapped = Wrap::Wrapped.new(operation_class, user_wrap)
8
8
 
9
9
  # connect `false` as an end event, when an exception stopped the wrap, for example.
@@ -13,7 +13,7 @@ class Trailblazer::Operation
13
13
  end
14
14
 
15
15
  module Wrap
16
- def self.Operation(block)
16
+ def self.create_operation(block)
17
17
  Class.new( Nested.operation_class, &block ) # Usually resolves to Trailblazer::Operation.
18
18
  end
19
19
 
@@ -28,10 +28,9 @@ class Trailblazer::Operation
28
28
 
29
29
  def call( (options, flow_options), **circuit_options )
30
30
  block_calling_wrapped = -> {
31
- args, circuit_options_with_wrap_static = Railway::TaskWrap.arguments_for_call( @operation, [options, flow_options], **circuit_options )
31
+ activity = @operation.decompose[:activity]
32
32
 
33
- # TODO: this is not so nice, still working out how to separate all those bits and pieces.
34
- @operation.instance_variable_get(:@process).( args, **circuit_options.merge(circuit_options_with_wrap_static) ) # FIXME: arguments_for_call don't return the full circuit_options, :exec_context gets lost.
33
+ activity.( [options, flow_options], **circuit_options )
35
34
  }
36
35
 
37
36
  # call the user's Wrap {} block in the operation.
@@ -1,20 +1,20 @@
1
- module Trailblazer
2
- class Activity
3
- module Task
4
- # Convenience functions for tasks. Totally optional.
1
+ # module Trailblazer
2
+ # class Activity
3
+ # module Task
4
+ # # Convenience functions for tasks. Totally optional.
5
5
 
6
- # Task::Binary aka "step"
7
- # Step is binary task: true=> Right, false=>Left.
8
- # Step call proc.(options, flow_options)
9
- # Step is supposed to run Option::KW, so `step` should be Option::KW.
10
- #
11
- # Returns task to call the proc with (options, flow_options), omitting `direction`.
12
- # When called, the task always returns a direction signal.
13
- def self.Binary(step, on_true=Activity::Right, on_false=Activity::Left)
14
- ->(*args) do # Activity/Task interface.
15
- [ step.(*args) ? on_true : on_false, *args ] # <=> Activity/Task interface
16
- end
17
- end
18
- end
19
- end
20
- end
6
+ # # Task::Binary aka "step"
7
+ # # Step is binary task: true=> Right, false=>Left.
8
+ # # Step call proc.(options, flow_options)
9
+ # # Step is supposed to run Option::KW, so `step` should be Option::KW.
10
+ # #
11
+ # # Returns task to call the proc with (options, flow_options), omitting `direction`.
12
+ # # When called, the task always returns a direction signal.
13
+ # def self.Binary(step, on_true=Activity::Right, on_false=Activity::Left)
14
+ # ->(*args) do # Activity/Task interface.
15
+ # [ step.(*args) ? on_true : on_false, *args ] # <=> Activity/Task interface
16
+ # end
17
+ # end
18
+ # end
19
+ # end
20
+ # end
@@ -1,3 +1,3 @@
1
1
  module Trailblazer
2
- VERSION = "2.1.0.beta1"
2
+ VERSION = "2.1.0.beta2"
3
3
  end
@@ -49,11 +49,6 @@ class DocsNestedOperationTest < Minitest::Spec
49
49
  result["contract.default"].model.must_equal result[:model]
50
50
  end
51
51
 
52
- it "provides all steps for Introspect" do
53
- Trailblazer::Activity::Trace.compute_debug( Edit ).values.must_equal [{:id=>"model.build"}, {:id=>"contract.build"}]
54
- Trailblazer::Activity::Trace.compute_debug( Update ).values.must_equal [{:id=>"Nested(DocsNestedOperationTest::Edit)"}, {:id=>"contract.default.validate"}, {:id=>"persist.save"}, {:id=>"model.build"}, {:id=>"contract.build"}, {:id=>"contract.default.params_extract"}, {:id=>"contract.default.call"}]
55
- end
56
-
57
52
  #- test Edit circuit-level.
58
53
  it do
59
54
  signal, (result, _) = Edit.__call__( [Trailblazer::Context( params: {id: 1} ), {}] )
@@ -145,10 +140,10 @@ class NestedOutput < Minitest::Spec
145
140
 
146
141
  #:output
147
142
  class Update < Trailblazer::Operation
148
- step Nested( Edit, output: ->(options, **) do
143
+ step Nested( Edit, output: ->( ctx, ** ) do
149
144
  {
150
- "contract.my" => options["contract.default"],
151
- model: options[:model]
145
+ "contract.my" => ctx["contract.default"],
146
+ model: ctx[:model]
152
147
  }
153
148
  end )
154
149
  step Contract::Validate( name: "my" )
@@ -171,11 +166,9 @@ end
171
166
  class NestedWithCallableTest < Minitest::Spec
172
167
  Song = Struct.new(:id, :title)
173
168
 
174
- class Song
175
- module Contract
176
- class Create < Reform::Form
177
- property :title
178
- end
169
+ module Song::Contract
170
+ class Create < Reform::Form
171
+ property :title
179
172
  end
180
173
  end
181
174
 
@@ -229,8 +222,6 @@ class NestedWithCallableTest < Minitest::Spec
229
222
  #---
230
223
  #:callable-builder
231
224
  class MyBuilder
232
- extend Uber::Callable
233
-
234
225
  def self.call(options, current_user:nil, **)
235
226
  current_user.admin? ? Create::Admin : Create::NeedsModeration
236
227
  end
@@ -248,6 +239,49 @@ class NestedWithCallableTest < Minitest::Spec
248
239
  it { Delete.(params: {}, current_user: admin) .inspect("x").must_equal %{<Result:true [nil] >} }
249
240
  end
250
241
 
242
+ class NestedWithCallableAndInputTest < Minitest::Spec
243
+ Memo = Struct.new(:title, :text, :created_by)
244
+
245
+ class Memo::Upsert < Trailblazer::Operation
246
+ step Nested( :operation_class, input: :input_for_create )
247
+
248
+ def operation_class( ctx, ** )
249
+ ctx[:id] ? Update : Create
250
+ end
251
+
252
+ # only let :title pass through.
253
+ def input_for_create( ctx )
254
+ { title: ctx[:title] }
255
+ end
256
+
257
+ class Create < Trailblazer::Operation
258
+ step :create_memo
259
+
260
+ def create_memo( ctx, ** )
261
+ ctx[:model] = Memo.new(ctx[:title], ctx[:text], :create)
262
+ end
263
+ end
264
+
265
+ class Update < Trailblazer::Operation
266
+ step :find_by_title
267
+
268
+ def find_by_title( ctx, ** )
269
+ ctx[:model] = Memo.new(ctx[:title], ctx[:text], :update)
270
+ end
271
+ end
272
+ end
273
+
274
+ it "runs Create without :id" do
275
+ Memo::Upsert.( title: "Yay!" ).inspect(:model).
276
+ must_equal %{<Result:true [#<struct NestedWithCallableAndInputTest::Memo title=\"Yay!\", text=nil, created_by=:create>] >}
277
+ end
278
+
279
+ it "runs Update without :id" do
280
+ Memo::Upsert.( id: 1, title: "Yay!" ).inspect(:model).
281
+ must_equal %{<Result:true [#<struct NestedWithCallableAndInputTest::Memo title=\"Yay!\", text=nil, created_by=:update>] >}
282
+ end
283
+ end
284
+
251
285
  # builder: Nested + deviate to left if nil / skip_track if true
252
286
 
253
287
  #---
data/test/test_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "pp"
1
2
  require "trailblazer"
2
3
  require "minitest/autorun"
3
4
 
data/trailblazer.gemspec CHANGED
@@ -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-operation", ">= 0.1.2", "< 0.2.0"
20
+ spec.add_dependency "trailblazer-operation", ">= 0.2.0", "< 0.3.0"
21
21
  spec.add_dependency "reform", ">= 2.2.0", "< 3.0.0"
22
22
  spec.add_dependency "declarative"
23
23
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailblazer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0.beta1
4
+ version: 2.1.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-20 00:00:00.000000000 Z
11
+ date: 2018-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trailblazer-operation
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.2
19
+ version: 0.2.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: 0.2.0
22
+ version: 0.3.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 0.1.2
29
+ version: 0.2.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: 0.2.0
32
+ version: 0.3.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: reform
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -157,6 +157,8 @@ extensions: []
157
157
  extra_rdoc_files: []
158
158
  files:
159
159
  - ".gitignore"
160
+ - ".rubocop.yml"
161
+ - ".rubocop_todo.yml"
160
162
  - ".travis.yml"
161
163
  - CHANGES.md
162
164
  - COMM-LICENSE
@@ -176,6 +178,7 @@ files:
176
178
  - lib/trailblazer/operation/contract.rb
177
179
  - lib/trailblazer/operation/deprecations.rb
178
180
  - lib/trailblazer/operation/guard.rb
181
+ - lib/trailblazer/operation/input_output.rb
179
182
  - lib/trailblazer/operation/model.rb
180
183
  - lib/trailblazer/operation/module.rb
181
184
  - lib/trailblazer/operation/nested.rb