<commit_before>class AppSent
  class ConfigFile
    attr_reader :data

    CONFIG_NOT_FOUND_ERROR_MSG      = "missing config file '%s'"
    ENVIRONMENT_NOT_FOUND_ERROR_MSG = "config file '%s' has no '%s' environment"
    WRONG_CONFIG_ERROR_MSG          = "wrong config file '%s':\n"

    def initialize config_dir, config_file_name, environment, type, &block
      @config_dir, @config_file_name, @environment, @type, @block = config_dir, config_file_name, (environment && environment.to_sym), type, block

      @type ||= Hash
      raise "params #{@type} and block given" if block_given? and not @type==Hash
      @path_to_config = File.join(@config_dir,@config_file_name+'.yml')
    end

    def valid?
      return @checked if defined?(@checked)

      yaml_data = YAML.load_file(@path_to_config)
      yaml_data.symbolize_keys!

      @data = yaml_data[@environment]

      @checked = if @data.instance_of?(@type)
		   @data.symbolize_keys! if @type==Hash
		   if @block
		     self.instance_exec(&@block)
		     @self_error_msg = WRONG_CONFIG_ERROR_MSG % relative_path_to_config
		     options.ask_all? { |option| option.valid? }
		   else
		     true
		   end
		 else
		   false
		 end
    rescue NoMethodError, "undefined method `symbolize_keys!' for false:FalseClass"
      # yaml is not valid YAML file, TODO change error message
      @self_error_msg = ENVIRONMENT_NOT_FOUND_ERROR_MSG % [relative_path_to_config,@environment]
      @checked = false
    rescue Errno::ENOENT
      @self_error_msg = CONFIG_NOT_FOUND_ERROR_MSG % relative_path_to_config
      @checked = false
    end

    def options
      @options ||= []
    end

    def constantized
      @config_file_name.upcase
    end

    def error_message
      @self_error_msg += options.map { |o| o.valid? ? nil : o.error_message }.compact.join("\n")<commit_msg>fixed 1.8.7 issue<commit_after>class AppSent
  class ConfigFile
    attr_reader :data

    CONFIG_NOT_FOUND_ERROR_MSG      = "missing config file '%s'"
    ENVIRONMENT_NOT_FOUND_ERROR_MSG = "config file '%s' has no '%s' environment"
    WRONG_CONFIG_ERROR_MSG          = "wrong config file '%s':\n"

    def initialize config_dir, config_file_name, environment, type, &block
      @config_dir, @config_file_name, @environment, @type, @block = config_dir, config_file_name, (environment && environment.to_sym), type, block

      @type ||= Hash
      raise "params #{@type} and block given" if block_given? and not @type==Hash
      @path_to_config = File.join(@config_dir,@config_file_name+'.yml')
    end

    def valid?
      return @checked if defined?(@checked)

      yaml_data = YAML.load_file(@path_to_config)
      if yaml_data.is_a?(Hash)
	yaml_data.symbolize_keys!
      else
	# yaml is not valid YAML file, TODO change error message
	@self_error_msg = ENVIRONMENT_NOT_FOUND_ERROR_MSG % [relative_path_to_config,@environment]
	return @checked = false
      end

      @data = yaml_data[@environment]

      @checked = if @data.instance_of?(@type)
		   @data.symbolize_keys! if @type==Hash
		   if @block
		     self.instance_exec(&@block)
		     @self_error_msg = WRONG_CONFIG_ERROR_MSG % relative_path_to_config
		     options.ask_all? { |option| option.valid? }
		   else
		     true
		   end
		 else
		   false
		 end
    rescue Errno::ENOENT
      @self_error_msg = CONFIG_NOT_FOUND_ERROR_MSG % relative_path_to_config
      @checked = false
    end

    def options
      @options ||= []
    end

    def constantized
      @config_file_name.upcase
    end

    def error_message
      @self_error_msg += options.map { |o| o.valid? ? nil : o.error_message }.compact.join("\n")
{'fraction_non_alphanumeric': 0.09853712393044438, 'fraction_numerical': 0.0008280430582390284, 'mean_word_length': 3.243559718969555, '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': '3365105', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1170, 'n_words': 273}