module Flucti module Parameters extend self extend Utilities def store_dir @store_dir ||= begin options = [] options << Pathname(ENV['APPDATA']) / 'Flucti' if ENV['APPDATA'] options << Pathname(ENV['HOME']) / '.flucti' if ENV['HOME'] located = options.find { |dir| dir.directory? } || options.find { |dir| dir.dirname.directory? } located ||= Pathname(Dir.tmpdir) / 'flucti' located.mkpath located end end def data_store @data_store ||= store_dir / 'parameters.yml' end def fetch(key) cache[key.to_s] end def store(key, value) cache[key.to_s] = value data_store.open("w") { |f| f << YAML.dump(cache) } end private def cache @cache ||= (YAML.load_file(data_store) if data_store.exist?) || {} end end end