class At_email::Config::Config_File
Public Instance Methods
get_config()
click to toggle source
# File lib/at_email/config/config_file.rb, line 6 def get_config() if File.exist?($options.config_file) contents = File.read($options.config_file) config = JSON.parse(contents, symbolize_names: true) else raise "Config file does not exist: " + $options.config_file end default_config_file_path = $app_path + '/' + At_email::DEFAULT_CONFIG_FILE if File.exist?(default_config_file_path) default_config_contents = File.read(default_config_file_path) default_config = JSON.parse(default_config_contents, symbolize_names: true) else raise "Default config file does not exist: " + default_config_file_path end config.each do |key, value| if !default_config[key] raise 'Config Error: Property: ' + key.to_s + ' is not a valid configuration option for this system' end end default_config.each do |key, data| if !config[key] && data[:value] config[key] = data[:value] end end default_config.each do |key, data| if config[key] if data[:type] if data[:type] === 'boolean' if ![true, false].include? config[key] raise 'Config Error: Property: ' + key.to_s + ' is not type: boolean - config value: ' + config[key].to_s end end if data[:type] === 'numeric' if !config[key].is_a? Numeric raise 'Config Error: Property: ' + key.to_s + ' is not type: numeric - config value: ' + config[key].to_s end if data[:min_value] if config[key] < data[:min_value] raise 'Config Error: Property: ' + key.to_s + ' is below minimum value: ' + data[:min_value].to_s + ' - config value: ' + config[key].to_s end end if data[:max_value] if config[key] > data[:max_value] raise 'Config Error: Property: ' + key.to_s + ' is above maximum value: ' + data[:max_value].to_s + ' - config value: ' + config[key].to_s end end end if data[:type] === 'string' if !config[key].is_a? String raise 'Config Error: Property: ' + key.to_s + ' is not type: string - value: ' + config[key].to_s end if data[:min_length] if config[key].length < data[:min_length] raise 'Config Error: Property: ' + key.to_s + ' is below minimum lenth: ' + data[:min_length].to_s + ' - config value: ' + config[key].to_s end end if data[:max_length] if config[key].length > data[:max_length] raise 'Config Error: Property: ' + key.to_s + ' is above minimum lenth: ' + data[:max_length].to_s + ' - config value: ' + config[key].to_s end end end if data[:type] === 'path' if data[:path_type] if data[:path_type] === 'dir' if !Dir.exists?(config[key].to_s) raise 'Config Error: Property: ' + key.to_s + ' is not a directory path - config value: ' + config[key].to_s end end if data[:path_type] === 'file' if !File.exists?(config[key].to_s) raise 'Config Error: Property: ' + key.to_s + ' is not a file path - config value: ' + config[key].to_s end end end end end end end output = {} config.sort_by { |k, v| k }.each do |key, value| output[key] = value end return output end