<commit_before>require 'uri'
require 'json/add/core'

module Pact
  module Consumer
    class MockProducer

      attr_reader :uri

      def initialize(pactfile_root)
        @pactfile_root = pactfile_root
        @interactions = {}
      end

      def consumer(consumer_name)
        @consumer_name = consumer_name
        self
      end

      def assuming_a_service(service_name)
        @service_name = service_name
        self
      end

      def at(url)
        @uri = URI(url)
        self
      end

      def upon_receiving(description)
        @interactions[description] ||= Interaction.new(self, description)
      end

      def update_pactfile
        File.open(pactfile_path, 'w') do |f|
          f.write JSON.dump(@interactions.values)
        end
      end

      def pactfile_path
        raise 'You must first specify a consumer and service name' unless @consumer_name and @service_name
        @pactfile_path ||= File.join(@pactfile_root, "#{filenamify(@consumer_name)}-#{filenamify(@service_name)}.json")
      end

      private

      def filenamify name
        name.downcase.gsub(/\s/, '_')<commit_msg>Pretty print pact files, for easier visual diffing<commit_after>require 'uri'
require 'json/add/core'

module Pact
  module Consumer
    class MockProducer

      attr_reader :uri

      def initialize(pactfile_root)
        @pactfile_root = pactfile_root
        @interactions = {}
      end

      def consumer(consumer_name)
        @consumer_name = consumer_name
        self
      end

      def assuming_a_service(service_name)
        @service_name = service_name
        self
      end

      def at(url)
        @uri = URI(url)
        self
      end

      def upon_receiving(description)
        @interactions[description] ||= Interaction.new(self, description)
      end

      def update_pactfile
        File.open(pactfile_path, 'w') do |f|
          f.write JSON.pretty_generate(@interactions.values)
        end
      end

      def pactfile_path
        raise 'You must first specify a consumer and service name' unless @consumer_name and @service_name
        @pactfile_path ||= File.join(@pactfile_root, "#{filenamify(@consumer_name)}-#{filenamify(@service_name)}.json")
      end

      private

      def filenamify name
        name.downcase.gsub(/\s/, '_')
{'fraction_non_alphanumeric': 0.08441558441558442, 'fraction_numerical': 0.0, 'mean_word_length': 2.3492753623188407, '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': '2995665', 'n_tokens_mistral': 725, 'n_tokens_neox': 685, 'n_words': 161}