@@ -66,11 +66,6 @@ def merge(variables)
6666 Context . new ( shadowed , mutable . merge ( variables ) )
6767 end
6868
69- def ___merge! ( variable , value )
70- self [ variable ] = value
71- self
72- end
73-
7469 def decompose
7570 return shadowed , mutable
7671 end
@@ -188,10 +183,9 @@ def self.call(task, ctx, **)
188183 result = task . ( application_ctx , **application_ctx . to_h )
189184 # pp application_ctx
190185
191- return ctx . ___merge! ( :value , result ,
192- # application_ctx: application_ctx
193- ) , nil # DISCUSS: value. FIXME: redundant to INVOKER___STEP_INTERFACE_ON_EXEC_CONTEXT
186+ ctx [ :value ] = result
194187
188+ return ctx , nil # DISCUSS: value. FIXME: redundant to INVOKER___STEP_INTERFACE_ON_EXEC_CONTEXT
195189 end
196190 end
197191
@@ -263,34 +257,20 @@ def self.call(ctx, value:, **)
263257 end
264258 end
265259
266- class Model___Input
267- def self . call ( ctx , ** ) # TODO: remove me! use Processor scoping
268- ctx = Trailblazer . Context ( ctx )
269-
270- return ctx , nil
271- end
272- end
273-
274- class Model___Output
275- def self . call ( ctx , **)
276- ctx , _ = ctx . decompose
277- puts " unscope___ discarding keys #{ _ . keys . inspect } [Model___Output]"
278- return ctx , nil
279- end
280- end
281-
282260 class Create
283261 def model ( ctx , params :, **kws )
284262 ctx [ :spam ] = false
285263 ctx [ :model ] = "Object #{ params [ :id ] } / #{ kws . inspect } "
286264 end
287265
288- def my_model_input ( ctx , params :, **)
266+ # Add params[:slug],
267+ def my_model_input ( ctx , params :, slug :, **)
289268 {
290- params : { id : params [ : slug] }
269+ params : params . merge ( slug : slug )
291270 }
292271 end
293272
273+ # Out() => [:model]
294274 def my_model_output ( ctx , model :, **)
295275 {
296276 model : model
@@ -318,32 +298,13 @@ def save_original_application_ctx(ctx, application_ctx:, **)
318298 return ctx , nil
319299 end
320300
321- # Reinstate the original working ctx with a new application_ctx
322- def unscope___ ( ctx , tmp , application_ctx :, aggregate :, **)
323- original , _ = ctx . decompose
324- puts " unscope___ discarding keys #{ _ . keys . inspect } "
325-
326- ctx = original . merge ( application_ctx : Trailblazer ::Context ( aggregate ) ) # FIXME: separate step.
327-
328- return ctx , nil , tmp
329- end
330-
331- # def create_input_ctx(ctx, aggregate:, **)
332-
333- # end
334-
335301 def swap___ ( ctx , application_ctx :, original_application_ctx :, aggregate :, **)
336302 # new_application_ctx = original_application_ctx.merge(aggregate) # DISCUSS: how to write on outer ctx?
337303 aggregate . each do |k , v |
338304 original_application_ctx [ k ] = v # FIXME: should we use Context#merge here? do we want a new ctx?
339305
340306 end
341307
342-
343- # before_output, _ = ctx.decompose # FIXME: couldn't we get the original_application_ctx from here?
344- # raise before_output.inspect
345-
346- # ctx = original.merge(application_ctx: new_application_ctx)
347308 ctx [ :application_ctx ] = original_application_ctx
348309
349310 return ctx , nil
@@ -358,35 +319,16 @@ def create_application_ctx(ctx, aggregate:, **)
358319 end
359320 Io = IO___ . new
360321
361- module TaskWrap
362- def self . emit_signal_from_ctx ( ctx , signal :, **) # DISCUSS: do we really want this?
363- puts "@@@@@ ||||#{ signal . inspect } "
364- return ctx , signal # FIXME: thiiiiiiiiiiiiiiiiiis neeeeds to be the last tw step.
365- end
366-
367- def self . FIXME_emit_signal_from_ctx___AND_UNSCOPE ( ctx , signal :, **) # DISCUSS: do we really want this?
368- puts "<<<<<<<<< signaL: #{ signal . inspect } "
369- ctx , _ = ctx . decompose
370- puts " FIXME_emit_signal_from_ctx___AND_UNSCOPE discarding keys #{ _ . keys . inspect } "
371- puts " new ctx: #{ ctx } "
372-
373- return ctx , signal # FIXME: thiiiiiiiiiiiiiiiiiis neeeeds to be the last tw step.
374- end
375- end
376-
377322 # In() => :my_model_input
378323 my_model_input_pipe = pipeline_circuit (
379- # [:input, Model___Input], # DISCUSS: can we somehow save these steps?
380324 [ :invoke_instance_method , :my_model_input , INVOKER___STEP_INTERFACE_ON_EXEC_CONTEXT , { exec_context : Create . new } ] ,
381- # [:compute_binary_signal, ComputeBinarySignal],
382325 [ :add_value_to_aggregate , :add_value_to_aggregate , INVOKER___CIRCUIT_INTERFACE_ON_EXEC_CONTEXT , { exec_context : Io , use_application_ctx___ : false } ] ,
383- # [:output, Model___Output],
384326 )
385327 # In() => MoreModelInput
386328 class MoreModelInput
387- def self . call ( ctx , params :, **)
329+ def self . call ( ctx , slug :, **)
388330 {
389- more : params . inspect
331+ more : slug
390332 }
391333 end
392334 end
@@ -403,16 +345,13 @@ def self.call(ctx, params:, **)
403345
404346 model_input_pipe = pipeline_circuit (
405347 [ :save_original_application_ctx , :save_original_application_ctx , INVOKER___CIRCUIT_INTERFACE_ON_EXEC_CONTEXT , { exec_context : Io } ] ,
406- # [:scope, Model___Input], # scope, so we don't pollute anything.
407348 [ :init_aggregate , :init_aggregate , INVOKER___CIRCUIT_INTERFACE_ON_EXEC_CONTEXT , { exec_context : Io } ] ,
408349 [ :my_model_input , my_model_input_pipe , Circuit ::Processor , { scope : true , emit_to_outer_ctx : [ :aggregate ] } ] , # user filter.
409350 [ :more_model_input , more_model_input_pipe , Circuit ::Processor , { scope : true , emit_to_outer_ctx : [ :aggregate ] } ] , # user filter.
410- # [:unscope, :unscope___, INVOKER___CIRCUIT_INTERFACE_ON_EXEC_CONTEXT, {exec_context: Io}]
411351 [ :create_application_ctx , :create_application_ctx , INVOKER___CIRCUIT_INTERFACE_ON_EXEC_CONTEXT , { exec_context : Io } ] ,
412352 )
413353
414354 model_output_pipe = pipeline_circuit (
415- # [:scope, Model___Input], # scope so we don't pollute
416355 [ :init_aggregate , :init_aggregate , INVOKER___CIRCUIT_INTERFACE_ON_EXEC_CONTEXT , { exec_context : Io } ] ,
417356 [ :my_model_output , my_model_output_pipe , Circuit ::Processor ] , # user filter.
418357 [ :swap___ , :swap___ , INVOKER___CIRCUIT_INTERFACE_ON_EXEC_CONTEXT , { exec_context : Io } ] ,
@@ -424,7 +363,7 @@ def self.call(ctx, params:, **)
424363# x.report("cix") {
425364 ctx , signal = Circuit ::Processor . ( model_input_pipe ,
426365 {
427- application_ctx : { params : { slug : 999 } , noise : true } ,
366+ application_ctx : { params : { song : { } } , noise : true , slug : "0x666" } ,
428367 } ,
429368 # {}, # tmp
430369 exec_context : create_instance = Create . new ,
@@ -441,10 +380,10 @@ def self.call(ctx, params:, **)
441380
442381 # raise ctx.inspect
443382 assert_equal ctx [ :application_ctx ] . class , Trailblazer ::Context ::Container # our In pipe's creation!
444- assert_equal ctx [ :application_ctx ] [ :more ] , "{:slug=>999} " # the more_model_input was called.
383+ assert_equal ctx [ :application_ctx ] [ :more ] , "0x666 " # the more_model_input was called.
445384 assert_equal ctx [ :original_application_ctx ] . class , Hash # the OG ctx is a Hash.
446385 assert_equal ctx . keys , [ :application_ctx , :original_application_ctx ]
447- assert_equal CU . inspect ( ctx ) , %({:application_ctx=>#<Trailblazer::Context::Container wrapped_options={:params=>{:id=>999 }, :more =>\" {:slug=>999} \" } mutable_options={}>, :original_application_ctx=>{:params=>{:slug=>999} , :noise=>true}})
386+ assert_equal CU . inspect ( ctx ) , %({:application_ctx=>#<Trailblazer::Context::Container wrapped_options={:params=>{:song=>{ }, :slug =>\" 0x666 \" }, :more=> \" 0x666 \" } mutable_options={}>, :original_application_ctx=>{:params=>{:song=>{}} , :noise=>true, :slug=> \" 0x666 \" }})
448387
449388 # this is what happens in the actual {:model} step.
450389 ctx [ :application_ctx ] [ :model ] = Object
@@ -454,7 +393,8 @@ def self.call(ctx, params:, **)
454393 emit_to_outer_ctx : [ :application_ctx ] ,
455394 )
456395
457- assert_equal ctx . inspect , %({:application_ctx=>{:params=>{:slug=>999}, :noise=>true, :model=>Object}, :original_application_ctx=>{:params=>{:slug=>999}, :noise=>true, :model=>Object}})
396+ # FIXME!!!!!!!!!!!!!!!!!!!!!! original_application_ctx shooouldn't contain {model}?
397+ assert_equal ctx . inspect , %({:application_ctx=>{:params=>{:song=>{}}, :noise=>true, :slug=>"0x666", :model=>Object}, :original_application_ctx=>{:params=>{:song=>{}}, :noise=>true, :slug=>"0x666", :model=>Object}})
458398
459399
460400
@@ -488,34 +428,21 @@ def self.call(ctx, model:, **)
488428 end
489429
490430 model_pipe = pipeline_circuit (
491- # [:input, Model___Input], # DISCUSS: can we somehow save these steps?
492431 [ :input , model_input_pipe , Circuit ::Processor , { scope : true , emit_to_outer_ctx : [ :application_ctx , :original_application_ctx ] . freeze } ] , # change {:application_ctx}.
493432
494- # [:scope, Model___Input], # we don't want {:signal} later!
495433 [ :invoke_instance_method , :model , INVOKER___STEP_INTERFACE_ON_EXEC_CONTEXT , { exec_context : Create . new } ] ,
496434 [ :compute_binary_signal , ComputeBinarySignal ] ,
497- # [:output, Model___Output], # DISCUSS: can we somehow save these steps?
498435 [ :output , model_output_pipe , Circuit ::Processor , { scope : true , emit_to_outer_ctx : [ :application_ctx ] . freeze } ] ,
499- # [:asdf, ->(ctx, signal:, **) { pp ctx; raise "why is there a signal?" }],
500- # [:emit_signal_from_ctx, :FIXME_emit_signal_from_ctx___AND_UNSCOPE, INVOKER___CIRCUIT_INTERFACE_ON_EXEC_CONTEXT, {exec_context: TaskWrap}],
501- # [:unscope, Model___Output],
502436 )
503- # pp model_pipe
504437
505438 run_checks_pipe = pipeline_circuit (
506- # [:input, Model___Input],
507439 [ :invoke_instance_method , :run_checks , INVOKER___STEP_INTERFACE_ON_EXEC_CONTEXT ] , # FIXME: we're currenly assuming that exec_context is passed down.
508440 [ :compute_binary_signal , ComputeBinarySignal ] ,
509- # [:output, Model___Output],
510- # [:emit_signal_from_ctx, :FIXME_emit_signal_from_ctx___AND_UNSCOPE, INVOKER___CIRCUIT_INTERFACE_ON_EXEC_CONTEXT, {exec_context: TaskWrap}], # FIXME: {exec_context} currently bleeds into {title_length_ok_pipe}.
511441 )
512442
513443 title_length_ok_pipe = pipeline_circuit (
514- [ :input , Model___Input ] ,
515444 [ :invoke_instance_method , :title_length_ok? , INVOKER___STEP_INTERFACE_ON_EXEC_CONTEXT ] ,
516445 [ :compute_binary_signal , ComputeBinarySignal ] ,
517- # [:output, Model___Output],
518- [ :emit_signal_from_ctx , :FIXME_emit_signal_from_ctx___AND_UNSCOPE , INVOKER___CIRCUIT_INTERFACE_ON_EXEC_CONTEXT , { exec_context : TaskWrap } ] ,
519446 )
520447
521448 run_checks = [ :run_checks , run_checks_pipe , Circuit ::Processor , { scope : true , emit_to_outer_ctx : [ :application_ctx ] , emit_signal : true } ]
@@ -532,18 +459,13 @@ def self.call(ctx, model:, **)
532459 validate_circuit = Circuit . new ( map : validate_circuit , termini : [ FIXME_SUCCESS , FIXME_FAILURE ] , start_task : run_checks )
533460
534461 save_pipe = pipeline_circuit (
535- # [:input, Model___Input],
536462 [ :invoke_callable , Save , INVOKER___STEP_INTERFACE ] ,
537463 [ :compute_binary_signal , ComputeBinarySignal ] ,
538- # [:output, Model___Output],
539- # [:emit_signal_from_ctx, :emit_signal_from_ctx, INVOKER___CIRCUIT_INTERFACE_ON_EXEC_CONTEXT, {exec_context: TaskWrap}],
540464 )
541465
542- # create_pipe = [
543466 model = [ :Model , model_pipe , Circuit ::Processor , { exec_context : Create . new . freeze , scope : true , emit_to_outer_ctx : [ :application_ctx ] , emit_signal : true } , ] # TODO: circuit_options should be set outside of Create, in the canonical invoke.
544467 validate = [ :Validate , validate_circuit , Circuit ::Processor , { exec_context : Validate . new . freeze , scope : true , emit_to_outer_ctx : [ :application_ctx ] } , ] # TODO: always emit :application_ctx?
545468 save = [ :Save , save_pipe , Circuit ::Processor , { scope : true , emit_to_outer_ctx : [ :application_ctx ] , emit_signal : true } ] # check that we don't have circuit_options anymore here?
546- # ]
547469
548470 create_success_terminus = [ :create_success_terminus , CREATE_FIXME_SUCCESS = Circuit ::Terminus ::Success . new ( semantic : :success ) , INVOKER___CIRCUIT_INTERFACE , { } ]
549471 create_failure_terminus = [ :create_failure_terminus , CREATE_FIXME_FAILURE = Circuit ::Terminus ::Failure . new ( semantic : :failure ) , INVOKER___CIRCUIT_INTERFACE , { } ]
@@ -558,7 +480,7 @@ def self.call(ctx, model:, **)
558480
559481 create_circuit = Circuit . new ( map : create_circuit , termini : [ CREATE_FIXME_SUCCESS , CREATE_FIXME_FAILURE ] , start_task : model )
560482
561- ctx = { params : { id : 1 } }
483+ ctx = { params : { song : nil } , slug : "0x666" }
562484 create_ctx = {
563485 # exec_context: Create.new,
564486 application_ctx : ctx
@@ -568,16 +490,16 @@ def self.call(ctx, model:, **)
568490 # validation error:
569491 ctx , signal = Circuit ::Processor . ( create_circuit , create_ctx )
570492
571- assert_equal ctx [ :application_ctx ] , { :params => { :id => 1 } , : model=> "Object 1" , :errors => [ "Object 1 " , :song ] }
572- assert_equal ctx . keys , [ :application_ctx , :exec_context ]
493+ assert_equal ctx [ :application_ctx ] , { :params => { :song => nil } , slug : "0x666" , : model=> "Object / {:more=> \" 0x666 \" }" , :errors => [ "Object / {:more=> \" 0x666 \" } " , :song ] }
494+ assert_equal ctx . keys , [ :application_ctx ]
573495 assert_equal signal , CREATE_FIXME_FAILURE
574496
575497 # success:
576- ctx , signal = Circuit ::Processor . ( create_circuit , { application_ctx : _ctx = { params : { song : { title : "Uwe" } , id : 1 } } } )
498+ ctx , signal = Circuit ::Processor . ( create_circuit , { application_ctx : _ctx = { params : { song : { title : "Uwe" } , id : 1 } , slug : "0x666" } } )
577499
578- assert_equal ctx [ :application_ctx ] , { :params => { :song => { title : "Uwe" } , id : 1 } , : model=> "Object 1" , :save => "Object 1" }
500+ assert_equal ctx [ :application_ctx ] , { :params => { :song => { title : "Uwe" } , id : 1 } , slug : "0x666" , : model=> "Object 1 / {:more=> \" 0x666 \" }" , :save => "Object 1 / {:more=> \" 0x666 \" } " }
579501 assert_equal signal , CREATE_FIXME_SUCCESS
580- assert_equal ctx . keys , [ :application_ctx , :exec_context ]
502+ assert_equal ctx . keys , [ :application_ctx ]
581503
582504
583505 # save_pipe = [
@@ -628,16 +550,7 @@ def self.call(ctx, model:, **)
628550# pipe: 78046.2 i/s
629551# circuit: 65255.8 i/s - 1.20x (± 0.00) slower
630552
631-
632-
633- it "signal transport" do
634- my_compute_signal = -> ( ctx , **) { return ctx , "MySignal" }
635-
636- pipe = pipeline_circuit (
637- [ :compute_signal , my_compute_signal , INVOKER___CIRCUIT_INTERFACE ] ,
638- )
639553 end
640- end
641554
642555 class INVOKER___CIRCUIT_INTERFACE___INSTANCE_METHOD_ON_EXEC_CONTEXT # GREAT thing here, we can use it for businesss and for library tasks.
643556 def self . call ( ctx , flow_options , circuit_options , task :, **kwargs )
0 commit comments