<commit_before>require 'remote_database_cleaner/exceptions'

module RemoteDatabaseCleaner
  class Config

    attr_accessor :home, :https

    def initialize
      @home = default_home_config
      @https = false
    end

    def home_url
      raise_if_host_not_set
      if home[:port]
        "#{ hyper_text_transfer_protocal }://#{ home.fetch(:host) }:#{ home.fetch(:port) }#{ home.fetch(:end_point) }"
      else
        "#{ hyper_text_transfer_protocal }://#{ home.fetch(:host) }#{ home.fetch(:end_point) }"
      end
    end

    def to_hash
      { home:     home,
        home_url: home_url }
    end

    def raise_if_host_not_set
      raise RemoteDatabaseCleanerConfigError.new("RemoteDatabaseCleaner.config.home[:host] can not be nil") unless has_home?
    end

    def has_home?
      !home[:host].nil? && !(home[:host] == '') && !home[:end_point].nil? && !(home[:end_point] == '')
    end

    private

    def hyper_text_transfer_protocal
      https == true ? 'https' : 'http'
    end

    def default_home_config
      { :host      => nil,
        :port      => nil,
        :end_point => '/remote_database_cleaner/home/clean' }
    end
  end
end<commit_msg>Creates constant for default end point<commit_after>require 'remote_database_cleaner/exceptions'

module RemoteDatabaseCleaner
  class Config

    DEFAULT_END_POINT = '/remote_database_cleaner/home/clean'.freeze

    attr_accessor :home, :https

    def initialize
      @home = default_home_config
      @https = false
    end

    def home_url
      raise_if_host_not_set
      if home[:port]
        "#{ hyper_text_transfer_protocal }://#{ home.fetch(:host) }:#{ home.fetch(:port) }#{ home.fetch(:end_point) }"
      else
        "#{ hyper_text_transfer_protocal }://#{ home.fetch(:host) }#{ home.fetch(:end_point) }"
      end
    end

    def to_hash
      { home:     home,
        home_url: home_url }
    end

    def raise_if_host_not_set
      raise RemoteDatabaseCleanerConfigError.new("RemoteDatabaseCleaner.config.home[:host] can not be nil") unless has_home?
    end

    def has_home?
      !home[:host].nil? && !(home[:host] == '') && !home[:end_point].nil? && !(home[:end_point] == '')
    end

    private

    def hyper_text_transfer_protocal
      https == true ? 'https' : 'http'
    end

    def default_home_config
      { :host      => nil,
        :port      => nil,
        :end_point => DEFAULT_END_POINT }
    end
  end
end
{'fraction_non_alphanumeric': 0.12360939431396786, 'fraction_numerical': 0.0, 'mean_word_length': 2.729646697388633, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7541828', 'n_tokens_mistral': 797, 'n_tokens_neox': 793, 'n_words': 156}