lib/trailblazer/activity/dsl/linear/strategy.rb in trailblazer-activity-dsl-linear-1.0.0 vs lib/trailblazer/activity/dsl/linear/strategy.rb in trailblazer-activity-dsl-linear-1.1.0

- old
+ new

@@ -69,12 +69,12 @@ @state.update!(:sequence) { |*| sequence } @state.update!(:activity) { |*| activity } end # Used only once per strategy class body. - def compile_strategy!(strategy, **options) - options = strategy.OptionsForSequenceBuilder(**options) + def compile_strategy!(strategy_dsl, **options) + options = DSL.OptionsForSequenceBuilder(strategy_dsl, **options) compile_strategy_for!(**options) end def compile_strategy_for!(sequence:, normalizers:, **normalizer_options) @@ -125,10 +125,49 @@ compile_strategy!(strategy::DSL, normalizers: @state.get(:normalizers), **options) class_exec(&block) if block_given? end end + + def OptionsForSequenceBuilder(strategy_dsl, termini: nil, **user_options) + # DISCUSS: instead of calling a separate {initial_sequence} method we could make DSL strategies + # use the actual DSL to build up the initial_sequence, somewhere outside? Maybe using {:adds}? + strategy_options, strategy_termini = strategy_dsl.options_for_sequence_build(**user_options) # call Path.options_for_sequence_builder + + # DISCUSS: passing on Normalizers here is a service, not sure I like it. + initial_sequence = process_termini(strategy_options[:sequence], termini || strategy_termini, normalizers: strategy_dsl::Normalizers) + + { + step_interface_builder: method(:build_circuit_task_for_step), + adds: [], # DISCUSS: needed? + **user_options, + **strategy_options, # this might (and should!) override :track_name etc. + sequence: initial_sequence, + } + # no {:termini} left in options + end + + # If no {:termini} were provided by the Strategy user, we use the default + # {strategy_termini}. + def process_termini(sequence, termini, **options_for_append_terminus) + termini.each do |task, terminus_options| + sequence = append_terminus(sequence, task, **options_for_append_terminus, **terminus_options) + end + + return sequence + end + + def append_terminus(sequence, task, normalizers:, **options) + # DISCUSS: why are we requiring {:normalizers} here? only for invoking Normalizer.terminus + _sequence = Linear::Sequence::Builder.update_sequence_for(:terminus, task, options, normalizers: normalizers, sequence: sequence, normalizer_options: {}) + end + + # Wraps {user_step} into a circuit-interface compatible callable, a.k.a. "task". + def build_circuit_task_for_step(user_step) + Activity::Circuit::TaskAdapter.for_step(user_step, option: true) + end end # DSL + # FIXME: move to State#dup def self.copy(value, **) # DISCUSS: should that be here? value.copy end