<commit_before># frozen_string_literal: true

require "pathname"
require "dry/core/cache"

module Dry
  class View
    # @api private
    class Path
      extend Dry::Core::Cache
      include Dry::Equalizer(:dir, :root)

      attr_reader :dir, :root

      def self.[](path)
        if path.is_a?(self)
          path
        else
          new(path)
        end
      end

      def initialize(dir, root: dir)
        @dir = Pathname(dir)
        @root = root
      end

      def lookup(name, format, include_shared: true)
        fetch_or_store(dir, root, name, format) do
          template?(name, format) ||
            (include_shared && template?("shared/#{name}", format)) ||
            !root? && chdir("..").lookup(name, format)
        end<commit_msg>Stop infinitely looking for missing template and avoid SystemStackError<commit_after># frozen_string_literal: true

require "pathname"
require "dry/core/cache"

module Dry
  class View
    # @api private
    class Path
      extend Dry::Core::Cache
      include Dry::Equalizer(:dir, :root)

      attr_reader :dir, :root

      def self.[](path)
        if path.is_a?(self)
          path
        else
          new(path)
        end
      end

      def initialize(dir, root: dir)
        @dir = Pathname(dir)
        @root = Pathname(root)
      end

      def lookup(name, format, include_shared: true)
        fetch_or_store(dir, root, name, format) do
          template?(name, format) ||
            (include_shared && template?("shared/#{name}", format)) ||
            !root? && chdir("..").lookup(name, format)
        end
{'fraction_non_alphanumeric': 0.11904761904761904, 'fraction_numerical': 0.0, 'mean_word_length': 2.1623762376237625, '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': '3058105', 'n_tokens_mistral': 482, 'n_tokens_neox': 470, 'n_words': 127}