Sha256: 5a736a6e15363efcc753b9718ef5743e88f67df0fcd6314b2edf32b1c55c7627
Contents?: true
Size: 1.34 KB
Versions: 6
Compression:
Stored size: 1.34 KB
Contents
require "inifile" class Ppl::Application::Configuration USER_CONFIG = "~/.pplconfig" REPO_CONFIG = "./.ppl/config" def address_book_path default_config = default_configuration user_config = user_configuration path = default_config["address book"]["path"] if !user_config["address book"].nil? && !user_config["address book"]["path"].nil? path = File.expand_path(user_config["address book"]["path"]) end return path end def aliases user_aliases = user_configuration["aliases"] default_aliases = default_configuration["aliases"] if user_aliases.nil? default_aliases else user_aliases end end private def default_configuration { "aliases" => {}, "address book" => { "path" => Dir.pwd }, } end def user_configuration filename = File.expand_path(USER_CONFIG) config = {} if File.exists?(filename) config = IniFile::load(filename).to_h elsif File.exists?(xdg_path) config = IniFile::load(xdg_path).to_h end return config end def repository_configuration {} end def xdg_path default = "~/.config" custom = ENV["XDG_CONFIG_HOME"] if custom.nil? path = File.expand_path(default) else path = File.expand_path(custom) end File.join(path, "ppl", "config") end end
Version data entries
6 entries across 6 versions & 1 rubygems