<commit_before>require_relative 'generator'

module Aygabtu
  class ScopeActor
    def initialize(scope, routes, example_group)
      @scope, @routes, @example_group = scope, routes, example_group
    end

    def self.actions
      [:pass, :pend, :ignore]
    end

    def pass(pass_data)
      pass_data = @scope.pass_data.merge(pass_data)

      each_route do |route|
        route.touch!
        generator.generate_example(route, pass_data)
      end or generator.generate_pending_no_match_failing_example # @TODO
    end

    def ignore(reason)
      raise "Reason for ignoring must be a string" unless reason.is_a?(String)

      each_route(&:touch!)
    end

    def pend(reason)
      each_route do |route|
        route.touch!
        generator.generate_pending_example(route, reason)
      end or generator.generate_pending_no_match_failing_example
    end

    private

    def generator
      @generator ||= Generator.new(@scope, @example_group)
    end

    def each_route
      match = false
      @routes.each do |route|
        if @scope.matches_route?(route)
          match = true
          yield route
        end
      end

      match
    end
  end
end<commit_msg>scope actions work on segments now<commit_after>require_relative 'generator'

module Aygabtu
  class ScopeActor
    def initialize(scope, routes, example_group)
      @scope, @routes, @example_group = scope, routes, example_group
    end

    def self.actions
      [:pass, :pend, :ignore]
    end

    def pass(pass_data)
      each_empty_scope_segment do |scope, generator|
        generator.generate_pending_no_match_failing_example # @TODO
      end

      each_scope_segment_and_route do |scope, generator, route|
        pass_data = @scope.pass_data.merge(pass_data)

        route.touch!
        generator.generate_example(route, pass_data)
      end
    end

    def ignore(reason)
      raise "Reason for ignoring must be a string" unless reason.is_a?(String)

      each_empty_scope_segment do |scope, generator|
        generator.generate_pending_no_match_failing_example # @TODO
      end

      each_scope_segment_and_route do |scope, generator, route|
        route.touch!
      end
    end

    def pend(reason)
      each_empty_scope_segment do |scope, generator|
        generator.generate_pending_no_match_failing_example
      end

      each_scope_segment_and_route do |scope, generator, route|
        route.touch!
        generator.generate_pending_example(route, reason)
      end
    end

    private

    def each_scope_segment_and_route
      segments_generators_routes.each do |segment, generator, routes|
        routes.each { |route| yield segment, generator, route }
      end
    end

    def each_empty_scope_segment
      segments_generators_routes.each do |segment, generator, routes|
        next unless routes.empty?

        yield segment, generator
      end
    end

    def segments_generators_routes
      @segments_and_generators ||= @scope.segments.map do |segment|
        generator = Generator.new(segment, @example_group)
        routes = @routes.select { |route| segment.matches_route?(route) }

        [segment, generator, routes]
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.07017543859649122, 'fraction_numerical': 0.0, 'mean_word_length': 2.7742316784869976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2729967', 'n_tokens_mistral': 953, 'n_tokens_neox': 938, 'n_words': 234}