class Hcheck::Configuration
configuration class that loads configs via various ways initializes service classes from config
Constants
- DEFAULT_CONFIG_PATH
- DEFAULT_HCHECK_DIR
Attributes
services[R]
Public Class Methods
generate_config()
click to toggle source
# File lib/hcheck/configuration.rb, line 45 def generate_config FileUtils.copy_file(Gem.loaded_specs['hcheck'].gem_dir + '/hcheck.sample.yml', DEFAULT_CONFIG_PATH) puts "Generated #{DEFAULT_CONFIG_PATH}" end
load(config)
click to toggle source
# File lib/hcheck/configuration.rb, line 23 def load(config) Hcheck.configure config end
load_argv(args)
click to toggle source
# File lib/hcheck/configuration.rb, line 27 def load_argv(args) load_file(args[1].strip) if argv_config_present?(args) end
load_default()
click to toggle source
# File lib/hcheck/configuration.rb, line 35 def load_default load_file(DEFAULT_CONFIG_PATH) end
load_file(path)
click to toggle source
# File lib/hcheck/configuration.rb, line 31 def load_file(path) load read(path) end
new(config)
click to toggle source
# File lib/hcheck/configuration.rb, line 15 def initialize(config) @services = config.map do |key, options| options = [options] unless options.is_a?(Array) options.map { |o| Service.new(key, o) } end.flatten end
read(path)
click to toggle source
# File lib/hcheck/configuration.rb, line 39 def read(path) YAML.safe_load(ERB.new(File.read(path)).result, [Symbol]) || {} rescue StandardError => e raise Hcheck::Errors::ConfigurationError, e end
Private Class Methods
argv_config_present?(argvs)
click to toggle source
# File lib/hcheck/configuration.rb, line 52 def argv_config_present?(argvs) !argvs.empty? && argvs[0].match(/-+(config|c)/i) end