<commit_before>require 'rest-client'
require 'mixlib/authentication'
require 'yajl'
require 'cgi'

require 'spice/authentication'
require 'spice/chef'

require 'spice/core_ext/hash'

require 'spice/role'
require 'spice/client'
require 'spice/cookbook'
require 'spice/data_bag'
require 'spice/node'
require 'spice/search'
require 'spice/connection'

require 'spice/version'
require 'spice/mock'

module Spice

  class << self
    attr_writer :host, :port, :scheme, :url_path, :client_name, :connection, :key_file, :raw_key

    def default_host
      @default_host || "localhost"
    end

    def default_port
      @default_port || "4000"
    end

    def default_scheme
      @default_scheme || "http"
    end

    def default_url_path
      @default_url_path || ""
    end

    def host
      @host || default_host
    end

    def port
      @port || default_port
    end

    def scheme
      @scheme || default_scheme
    end

    def client_name
      @client_name
    end

    def key_file
      @key_file
    end

    def raw_key
      @raw_key
    end

    def key_file=(new_key_file)
      raw_key = File.read(new_key_file)
      assert_valid_key_format!(raw_key)
      @key_file = new_key_file
      @raw_key = raw_key
    end

    def chef_version
      @chef_version || "0.9.14"
    end
    
    def chef_version=(version)
      @chef_version = version
    end
    
    def url_path
      @url_path || default_url_path
    end

    def connection
      @connection
    end

    def connect!
      @connection = Connection.new(
        :url => "#{scheme}://#{host}:#{port}/#{url_path}",
        :client_name => client_name,
        :key_file => key_file
      )
    end

    def reset!
      @host = default_host
      @port = default_port
      @scheme = default_scheme
      @key_file = nil
      @client_name = nil
      @connection = nil
    end

    def setup
      yield self
    end

    def mock
      Spice::Mock.setup_mock_client
    end

    private

    def assert_valid_key_format!(raw_key)
      unless (raw_key =~ /\A-----BEGIN RSA PRIVATE KEY-----$/) &&
         (raw_key =~ /^-----END RSA PRIVATE KEY-----\Z/)
        msg = "The file #{key_file} does not contain a correctly formatted private key.\n"
        msg << "The key file should begin with '-----BEGIN RSA PRIVATE KEY-----' and end with '-----END RSA PRIVATE KEY-----'"
        raise ArgumentError, msg
      end
    end
  end
end
<commit_msg>reset! should also reset the url_path<commit_after>require 'rest-client'
require 'mixlib/authentication'
require 'yajl'
require 'cgi'

require 'spice/authentication'
require 'spice/chef'

require 'spice/core_ext/hash'

require 'spice/role'
require 'spice/client'
require 'spice/cookbook'
require 'spice/data_bag'
require 'spice/node'
require 'spice/search'
require 'spice/connection'

require 'spice/version'
require 'spice/mock'

module Spice

  class << self
    attr_writer :host, :port, :scheme, :url_path, :client_name, :connection, :key_file, :raw_key

    def default_host
      @default_host || "localhost"
    end

    def default_port
      @default_port || "4000"
    end

    def default_scheme
      @default_scheme || "http"
    end

    def default_url_path
      @default_url_path || ""
    end

    def host
      @host || default_host
    end

    def port
      @port || default_port
    end

    def scheme
      @scheme || default_scheme
    end

    def client_name
      @client_name
    end

    def key_file
      @key_file
    end

    def raw_key
      @raw_key
    end

    def key_file=(new_key_file)
      raw_key = File.read(new_key_file)
      assert_valid_key_format!(raw_key)
      @key_file = new_key_file
      @raw_key = raw_key
    end

    def chef_version
      @chef_version || "0.9.14"
    end
    
    def chef_version=(version)
      @chef_version = version
    end
    
    def url_path
      @url_path || default_url_path
    end

    def connection
      @connection
    end

    def connect!
      @connection = Connection.new(
        :url => "#{scheme}://#{host}:#{port}/#{url_path}",
        :client_name => client_name,
        :key_file => key_file
      )
    end

    def reset!
      @host = default_host
      @port = default_port
      @scheme = default_scheme
      @url_path = default_url_path
      @key_file = nil
      @client_name = nil
      @connection = nil
    end

    def setup
      yield self
    end

    def mock
      Spice::Mock.setup_mock_client
    end

    private

    def assert_valid_key_format!(raw_key)
      unless (raw_key =~ /\A-----BEGIN RSA PRIVATE KEY-----$/) &&
         (raw_key =~ /^-----END RSA PRIVATE KEY-----\Z/)
        msg = "The file #{key_file} does not contain a correctly formatted private key.\n"
        msg << "The key file should begin with '-----BEGIN RSA PRIVATE KEY-----' and end with '-----END RSA PRIVATE KEY-----'"
        raise ArgumentError, msg
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.10591583655214475, 'fraction_numerical': 0.0032526936369180726, 'mean_word_length': 2.238973008558262, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '2166186', 'n_tokens_mistral': 1667, 'n_tokens_neox': 1598, 'n_words': 419}