class Dip::Config
Constants
- CONFIG_DEFAULTS
- ConfigKeyMissingError
- DEFAULT_PATH
Attributes
work_dir[R]
Public Class Methods
load_yaml(file_path = path)
click to toggle source
# File lib/dip/config.rb, line 62 def load_yaml(file_path = path) return {} unless File.exist?(file_path) data = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new("4.0.0") YAML.safe_load( ERB.new(File.read(file_path)).result, aliases: true ) else YAML.safe_load( ERB.new(File.read(file_path)).result, [], [], true ) end data&.deep_symbolize_keys! || {} end
new(work_dir = Dir.pwd)
click to toggle source
# File lib/dip/config.rb, line 81 def initialize(work_dir = Dir.pwd) @work_dir = work_dir end
Public Instance Methods
exist?()
click to toggle source
# File lib/dip/config.rb, line 89 def exist? finder.exist? end
file_path()
click to toggle source
# File lib/dip/config.rb, line 85 def file_path finder.file_path end
to_h()
click to toggle source
# File lib/dip/config.rb, line 93 def to_h config end
Private Instance Methods
config()
click to toggle source
# File lib/dip/config.rb, line 111 def config return @config if @config raise Dip::Error, "Could not find dip.yml config" unless finder.exist? config = self.class.load_yaml(finder.file_path) unless Gem::Version.new(Dip::VERSION) >= Gem::Version.new(config.fetch(:version)) raise VersionMismatchError, "Your dip version is `#{Dip::VERSION}`, " \ "but config requires minimum version `#{config[:version]}`. " \ "Please upgrade your dip!" end override_finder = ConfigFinder.new(work_dir, override: true) config.deep_merge!(self.class.load_yaml(override_finder.file_path)) if override_finder.exist? @config = CONFIG_DEFAULTS.merge(config) end
config_missing_error(config_key)
click to toggle source
# File lib/dip/config.rb, line 130 def config_missing_error(config_key) msg = "config for %<key>s is not defined in %<path>s" % {key: config_key, path: finder.file_path} ConfigKeyMissingError.new(msg) end
finder()
click to toggle source
# File lib/dip/config.rb, line 107 def finder @finder ||= ConfigFinder.new(work_dir) end