Baguette::Configuration.
This commit is contained in:
parent
b457854f23
commit
8f566cbd79
@ -1,9 +1,46 @@
|
||||
require "colorize"
|
||||
require "yaml"
|
||||
|
||||
class Baguette::Context
|
||||
class_property verbosity = 1
|
||||
end
|
||||
|
||||
class Baguette::Configuration
|
||||
class Base
|
||||
include YAML::Serializable
|
||||
|
||||
# Check for provided file first,
|
||||
# then $XDG_CONFIG_HOME/<class>.yml,
|
||||
# then /etc/baguette/<class>.yml.
|
||||
def self.get(file : String?)
|
||||
filename = "/" + (self.name.downcase.gsub /baguette::configuration::/, "") + ".yml"
|
||||
directory = "/baguette"
|
||||
|
||||
suffix = "#{directory}#{filename}"
|
||||
user_configuration = (ENV["XDG_CONFIG_HOME"]? || "~/.config") + suffix
|
||||
system_configuration = "/etc#{suffix}"
|
||||
|
||||
if ! file.nil? && ! File.exists? file.not_nil!
|
||||
Baguette::Log.warning "Provided configuration file does not exist: #{file}"
|
||||
end
|
||||
|
||||
if ! file.nil? && File.exists? file.not_nil!
|
||||
Baguette::Log.info "Using configuration file: #{file}"
|
||||
self.from_yaml File.read(file.not_nil!)
|
||||
elsif File.exists? user_configuration
|
||||
Baguette::Log.info "Using user configuration: #{user_configuration}"
|
||||
self.from_yaml File.read(user_configuration)
|
||||
elsif File.exists? user_configuration
|
||||
Baguette::Log.info "Using system configuration: #{system_configuration}"
|
||||
self.from_yaml File.read(system_configuration)
|
||||
else
|
||||
Baguette::Log.warning "No configuration found"
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Baguette::Log
|
||||
# FIXME: Use log files.
|
||||
# FIXME: def log(), that puts stuff as-is in the logs.
|
||||
|
Loading…
Reference in New Issue
Block a user