Sha256: 32c2683f118573226eed73ebbed5df641200af0780834f66a63a4630340739ef

Contents?: true

Size: 1.76 KB

Versions: 1

Compression:

Stored size: 1.76 KB

Contents

module Trailblazer::V2_1
  class Activity::Magnetic::Builder
    # Maintain Builder instance plus Adds/Process/Outputs as immutable objects.
    module State
      def self.build(builder_class, normalizer, builder_options)
        builder, adds = builder_class.for(normalizer, builder_options) # e.g. Path.for(...) which creates a Builder::Path instance.

        recompile(builder.freeze, adds.freeze)
      end

      def self.add(builder, adds, strategy, polarizer, *args, &block)
        new_adds, *returned_options = builder.insert(strategy, polarizer, *args, &block) # TODO: move that out of here.

        adds = adds + new_adds

        recompile(builder, adds.freeze, returned_options)
      end

      private

      # @return {builder, Adds, Process, outputs}, returned_options
      def self.recompile(builder, adds, *args)
        circuit, outputs = recompile_circuit(adds)

        return builder, adds, circuit.freeze, outputs.freeze, *args
      end

      def self.recompile_circuit(adds)
        circuit, outputs = Recompile.( adds )
      end

      module Recompile
        # Recompile the circuit and outputs from the {ADDS} instance that collects circuit tasks and connections.
        #
        # @return [Process, Hash] The {Process} instance and its outputs hash.
        def self.call(adds)
          circuit, end_events = Finalizer.(adds)
          outputs             = recompile_outputs(end_events)

          return circuit, outputs
        end

        private

        def self.recompile_outputs(end_events)
          ary = end_events.collect do |evt|
            [
              semantic = evt.to_h[:semantic],
              Activity::Output(evt, semantic)
            ]
          end

          ::Hash[ ary ]
        end
      end # Recompile
    end # State
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trailblazer-future-2.1.0.rc1 lib/trailblazer/v2_1/activity/dsl/magnetic/builder/state.rb