class Config
Constants
- DEFAULT_CONF_FILE
- VALID_SETTINGS
Attributes
VALID_SETTINGS[R]
Public Class Methods
fhfile()
click to toggle source
# File lib/floatyhelper/config.rb, line 28 def self.fhfile "#{Etc.getpwuid.dir}/.floatyhelper.yaml" end
get_config_setting(setting)
click to toggle source
NOTE: Anything currently set with 'floatyhelper config set' will return a string, regardless of its intended type. Need to add typing one of these days.
# File lib/floatyhelper/config.rb, line 65 def self.get_config_setting(setting) data = load_data data['config'][setting] end
load_data()
click to toggle source
# File lib/floatyhelper/config.rb, line 32 def self.load_data File.write(fhfile, DEFAULT_CONF_FILE) unless File.exist?(fhfile) data = YAML.load_file(fhfile) # If someone is using an older version, ensure the conf file has # all the correct top-level keys. Only write it back if we modify # the data to add a top-level key. writeback = false ['config', 'vms', 'snapshots'].each do |key| if !data.keys.include?(key) data[key] = {} writeback = true end end # Config setting defaults VALID_SETTINGS.each do |setting, info| writeback = true if data['config'][setting].nil? data['config'][setting] ||= info['default'] end write_data(data) if writeback data end
set_config_setting(setting, value)
click to toggle source
# File lib/floatyhelper/config.rb, line 70 def self.set_config_setting(setting, value) data = load_data data['config'][setting] = value write_data(data) end
write_data(data)
click to toggle source
It is up to the calling function to ensure the data object being passed in is a properly formatted hash. It should only be used to modify after reading the current state with load_data.
# File lib/floatyhelper/config.rb, line 59 def self.write_data(data) File.write(fhfile, data.to_yaml) end