<commit_before>class Trailblazer::Operation
  # TODO: make Wrap::Subprocess not binary but actually wire its ends via the circuit.

  def self.Wrap(user_wrap, &block)
    operation_class = Wrap.build_wrapped_activity(block)

    Nested( Wrap::Wrapped.new(operation_class, user_wrap) )
  end

  module Wrap
    # behaves like an operation so it plays with Nested and simply calls the operation in the user-provided block.
    class Wrapped #< Trailblazer::Operation # FIXME: the inheritance is only to satisfy Nested( Wrapped.new )
      include Nested::Nestable

      def initialize(activity, user_wrap)
        @activity   = activity
        @user_wrap  = user_wrap
      end

      # The __call__ method is invoked by Nested.
      def __call__(direction, options, flow_options)
        block_calling_wrapped = -> {
          args = Railway::TaskWrap.arguments_for_call(@activity, direction, options, flow_options)

          @activity["__activity__"].( direction, *args )
        }


        returned = @user_wrap.( options, flow_options[:exec_context], &block_calling_wrapped )

        # returned could be
        #  1. the 1..>=3 Task interface result
        #  2. false
        #  3. true or something else, but not the Task interface (when rescue isn't needed)




        # legacy outcome.
        # FIXME: we return some "older version" of options here!
        # FIXME: make sure end_events[1] is the Failure end!
        return  end_events[1], options, flow_options if false === returned
<commit_msg>add comment.<commit_after>class Trailblazer::Operation
  # TODO: make Wrap::Subprocess not binary but actually wire its ends via the circuit.

  def self.Wrap(user_wrap, &block)
    operation_class = Wrap.build_wrapped_activity(block)

    Nested( Wrap::Wrapped.new(operation_class, user_wrap) )
  end

  module Wrap
    # behaves like an operation so it plays with Nested and simply calls the operation in the user-provided block.
    class Wrapped #< Trailblazer::Operation # FIXME: the inheritance is only to satisfy Nested( Wrapped.new )
      include Nested::Nestable

      def initialize(activity, user_wrap)
        @activity   = activity
        @user_wrap  = user_wrap
      end

      # The __call__ method is invoked by Nested.
      def __call__(direction, options, flow_options)
        block_calling_wrapped = -> {
          args = Railway::TaskWrap.arguments_for_call(@activity, direction, options, flow_options)

          @activity["__activity__"].( direction, *args )
        }


        returned = @user_wrap.( options, flow_options[:exec_context], &block_calling_wrapped )

        # returned could be
        #  1. the 1..>=3 Task interface result
        #  2. false
        #  3. true or something else, but not the Task interface (when rescue isn't needed)

        # legacy outcome.
        # FIXME: we return some "older version" of options here!
        # FIXME: make sure end_events[1] is the Failure end!
        return  end_events[1], options, flow_options if false === returned


        # TODO: test a proper return in the user_block!!!
{'fraction_non_alphanumeric': 0.08238728511190399, 'fraction_numerical': 0.0045410314628608495, 'mean_word_length': 2.9236641221374047, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4020000', 'n_tokens_mistral': 885, 'n_tokens_neox': 851, 'n_words': 293}