require 'logger' require 'psych' # add a deep_merge function to hashes # rubocop:disable Style/CaseEquality, Style/ClassAndModuleChildren class ::Hash def deep_merge(second) merger = proc do |_key, v1, v2| if Hash === v1 && Hash === v2 v1.merge(v2, &merger) else v2 end end merge(second, &merger) end end module PicsolveDockerBuilder # Base class for everything # * logging # * accessing config module Base def create_logger log = Logger.new(STDOUT) log.level = Logger::DEBUG log end def log @logger ||= create_logger end def config @config ||= read_config end def base_dir Dir.pwd end def config_path File.join(base_dir, '.docker-builder.yml') end def default_config {} end def validate_config(c) c end def read_config c = default_config path = config_path begin yaml = Psych.load_file path c = c.deep_merge(yaml) rescue Errno::ENOENT log.debug "can not find config at '#{path}'" end validate_config(c) end end end