<commit_before>class ExpectedKeysNotInContextError < StandardError; end
class PromisedKeysNotInContextError < StandardError; end

class ContextKeyVerifier
  class << self
    def verify_expected_keys_are_in_context(context, expected_keys)
      verify_keys_are_in_context(context, expected_keys) do |not_found_keys|
        fail ExpectedKeysNotInContextError, "expected #{format_keys(not_found_keys)} to be in the context"
      end
    end

    def verify_promised_keys_are_in_context(context, promised_keys)
      verify_keys_are_in_context(context, promised_keys) do |not_found_keys|
        fail PromisedKeysNotInContextError, "promised #{format_keys(not_found_keys)} to be in the context"
      end
    end

    private

    def verify_keys_are_in_context(context, keys)
      keys ||= context.keys

      not_found_keys = keys - context.keys
      unless not_found_keys.empty?
        yield not_found_keys
      end

      context
    end

    def format_keys(keys)
      keys.map{|k| ":#{k}"}.join(', ')
    end
  end
end<commit_msg>Putting the ContextKeyVerifier into the LightService module<commit_after>module LightService
  class ExpectedKeysNotInContextError < StandardError; end
  class PromisedKeysNotInContextError < StandardError; end

  class ContextKeyVerifier
    class << self
      def verify_expected_keys_are_in_context(context, expected_keys)
        verify_keys_are_in_context(context, expected_keys) do |not_found_keys|
          fail ExpectedKeysNotInContextError, "expected #{format_keys(not_found_keys)} to be in the context"
        end
      end

      def verify_promised_keys_are_in_context(context, promised_keys)
        verify_keys_are_in_context(context, promised_keys) do |not_found_keys|
          fail PromisedKeysNotInContextError, "promised #{format_keys(not_found_keys)} to be in the context"
        end
      end

      private

      def verify_keys_are_in_context(context, keys)
        keys ||= context.keys

        not_found_keys = keys - context.keys
        unless not_found_keys.empty?
          yield not_found_keys
        end

        context
      end

      def format_keys(keys)
        keys.map{|k| ":#{k}"}.join(', ')
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.06527651858567543, 'fraction_numerical': 0.0, 'mean_word_length': 3.467611336032389, 'pattern_counts': {'":': 2, '<': 11, '<?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': '661185', 'n_tokens_mistral': 672, 'n_tokens_neox': 658, 'n_words': 150}