<commit_before># frozen_string_literal: true

module Nanoc
  module Assertions
    class AssertionFailure < Nanoc::Int::Errors::InternalInconsistency
    end

    module Mixin
      def assert(assertion)
        return unless Nanoc::Core::ContractsSupport.enabled?

        unless assertion.call
          raise AssertionFailure, "assertion failed: #{assertion.class}"
        end
      end
    end

    class Base
      def call
        raise NotImplementedError
      end
    end

    class AllItemRepsHaveCompiledContent < Nanoc::Assertions::Base
      def initialize(compiled_content_cache:, item_reps:)
        @compiled_content_cache = compiled_content_cache
        @item_reps = item_reps
      end

      def call
        @item_reps.all? do |rep|
          @compiled_content_cache[rep]
        end
      end
    end

    class PathIsAbsolute < Nanoc::Assertions::Base
      def initialize(path:)
        @path = path
      end

      def call
        Pathname.new(@path).absolute?
      end
    end
  end
end
<commit_msg>Refactor: Add contracts to Assertions<commit_after># frozen_string_literal: true

module Nanoc
  module Assertions
    class AssertionFailure < Nanoc::Int::Errors::InternalInconsistency
    end

    module Mixin
      def assert(assertion)
        return unless Nanoc::Core::ContractsSupport.enabled?

        unless assertion.call
          raise AssertionFailure, "assertion failed: #{assertion.class}"
        end
      end
    end

    class Base
      def call
        raise NotImplementedError
      end
    end

    class AllItemRepsHaveCompiledContent < Nanoc::Assertions::Base
      include Nanoc::Core::ContractsSupport

      contract C::KeywordArgs[compiled_content_cache: C::Or[Nanoc::Core::CompiledContentCache, Nanoc::Core::TextualCompiledContentCache], item_reps: Nanoc::Core::ItemRepRepo] => C::Any
      def initialize(compiled_content_cache:, item_reps:)
        @compiled_content_cache = compiled_content_cache
        @item_reps = item_reps
      end

      contract C::None => C::Bool
      def call
        @item_reps.all? do |rep|
          @compiled_content_cache[rep]
        end
      end
    end

    class PathIsAbsolute < Nanoc::Assertions::Base
      include Nanoc::Core::ContractsSupport

      contract C::KeywordArgs[path: String] => C::Any
      def initialize(path:)
        @path = path
      end

      contract C::None => C::Bool
      def call
        Pathname.new(@path).absolute?
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.07745058491327148, 'fraction_numerical': 0.0, 'mean_word_length': 2.6363636363636362, 'pattern_counts': {'":': 0, '<': 9, '<?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': '5267156', 'n_tokens_mistral': 748, 'n_tokens_neox': 704, 'n_words': 167}