class Donjon::Settings
Attributes
path[R]
Public Class Methods
new(path = nil)
click to toggle source
# File lib/donjon/settings.rb, line 7 def initialize(path = nil) @path = path || _default_path @data = nil end
Public Instance Methods
configured?()
click to toggle source
# File lib/donjon/settings.rb, line 12 def configured? user_name && private_key && vault_path end
method_missing(method_name, *args, &block)
click to toggle source
# File lib/donjon/settings.rb, line 16 def method_missing(method_name, *args, &block) if method_name.to_s.end_with?('=') set(method_name.to_s.chop, *args) else get(method_name.to_s, *args) end end
respond_to?(method_name)
click to toggle source
# File lib/donjon/settings.rb, line 24 def respond_to?(method_name) !!(method_name.to_s =~ /[a-z][a-z_]*=?/) end
Private Instance Methods
_default_path()
click to toggle source
# File lib/donjon/settings.rb, line 56 def _default_path if ENV.fetch('DONJONRC', nil) Pathname.new(ENV.fetch('DONJONRC')).expand_path else _fallback_path end end
_fallback_path()
click to toggle source
# File lib/donjon/settings.rb, line 52 def _fallback_path Pathname.new('~').join('.donjonrc').expand_path end
_load()
click to toggle source
# File lib/donjon/settings.rb, line 42 def _load @path.exist? ? YAML.load_file(@path) : {} end
_save(data)
click to toggle source
# File lib/donjon/settings.rb, line 46 def _save(data) @data['timestamp'] = Time.now @path.parent.mkpath @path.write data.to_yaml end
get(key)
click to toggle source
# File lib/donjon/settings.rb, line 30 def get(key) @data ||= _load @data[key] end
set(key, value)
click to toggle source
# File lib/donjon/settings.rb, line 35 def set(key, value) @data ||= _load @data[key] = value _save(@data) value end