class Fontist::Config
Public Class Methods
new()
click to toggle source
# File lib/fontist/config.rb, line 5 def initialize @custom_values = load_config_file end
Public Instance Methods
custom_values()
click to toggle source
# File lib/fontist/config.rb, line 13 def custom_values @custom_values end
default_value(key)
click to toggle source
# File lib/fontist/config.rb, line 40 def default_value(key) default_values[key.to_sym] end
default_values()
click to toggle source
# File lib/fontist/config.rb, line 44 def default_values { fonts_path: Fontist.fontist_path.join("fonts"), open_timeout: 10, read_timeout: 10, google_fonts_key: nil } end
delete(key)
click to toggle source
# File lib/fontist/config.rb, line 34 def delete(key) @custom_values.delete(key.to_sym) persist end
fonts_path=(value)
click to toggle source
# File lib/fontist/config.rb, line 61 def fonts_path=(value) @custom_values[:fonts_path] = File.expand_path(value) end
load()
click to toggle source
# File lib/fontist/config.rb, line 57 def load @custom_values = load_config_file end
persist()
click to toggle source
# File lib/fontist/config.rb, line 51 def persist values = @custom_values.transform_keys(&:to_s) FileUtils.mkdir_p(File.dirname(Fontist.config_path)) File.write(Fontist.config_path, YAML.dump(values)) end
set(key, value)
click to toggle source
# File lib/fontist/config.rb, line 17 def set(key, value) attr = key.to_sym unless default_values.key?(attr) raise Errors::InvalidConfigAttributeError, "No such attribute '#{attr}' exists." end v = normalize_value(value) if respond_to?("#{attr}=") public_send("#{attr}=", v) else @custom_values[attr] = v end persist end
values()
click to toggle source
# File lib/fontist/config.rb, line 9 def values default_values.merge(@custom_values) end