Sha256: 9e19d9fb5b78dbb1c3ef558d21f0fef521b952cae643edae71a66eb68edc0b3e
Contents?: true
Size: 1.21 KB
Versions: 5
Compression:
Stored size: 1.21 KB
Contents
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_file ENV['DOCKER_BUILDER_FILE'] || '.docker-builder.yml' end def config_path File.join(base_dir, config_file) 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
Version data entries
5 entries across 5 versions & 1 rubygems