<commit_before>require_relative 'namespace'
require_relative 'controller'
require_relative 'path'
require_relative 'named'
require_relative 'passing'
require_relative 'requiring'
require_relative 'remaining'

module Aygabtu
  module Scope
    class Base
      def initialize(data)
        @data = data
      end

      def pass_data
        @data.fetch(:passing, {})
      end

      def self.blank_slate
        new(filters: [])
      end

      COMPONENTS = [
        Namespace,
        Controller,
        Path,
        Named,
        Passing,
        Requiring,
        Remaining
      ]

      module AlwaysMatches
        def matches_route?(route)
          true
        end
      end
      include AlwaysMatches

      module UnSegmented
        def segments_split_once
        end
      end
      include UnSegmented

      def segments
        if split_once = segments_split_once
          split_once.map(&:segments).reduce(:+)
        else
          [self]
        end
      end

      include(*COMPONENTS)

      @factory_methods = COMPONENTS.map do |component|
        component.try(:factory_method)
      end.compact

      class << self
        attr_reader :factory_methods
      end
    end
  end
end<commit_msg>refactor scope base<commit_after>require_relative 'namespace'
require_relative 'controller'
require_relative 'path'
require_relative 'named'
require_relative 'passing'
require_relative 'requiring'
require_relative 'remaining'

module Aygabtu
  module Scope
    class Base
      def initialize(data)
        @data = data
      end

      def pass_data
        @data.fetch(:passing, {})
      end

      def self.blank_slate
        new(filters: [])
      end

      COMPONENTS = [
        Namespace,
        Controller,
        Path,
        Named,
        Passing,
        Requiring,
        Remaining
      ]

      module BasicBehaviour
        # defines methods below COMPONENTS in the inheritance chain
        # so components can override and call super

        def matches_route?(route)
          true
        end

        def segments_split_once
        end
      end
      include BasicBehaviour

      include(*COMPONENTS)

      def segments
        if split_once = segments_split_once
          split_once.map(&:segments).reduce(:+)
        else
          [self]
        end
      end

      @factory_methods = COMPONENTS.map do |component|
        component.try(:factory_method)
      end.compact

      class << self
        attr_reader :factory_methods
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.06106264869151467, 'fraction_numerical': 0.0, 'mean_word_length': 1.9, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2611682', 'n_tokens_mistral': 721, 'n_tokens_neox': 689, 'n_words': 177}