class Fontist::Config
Public Class Methods
Source
# File lib/fontist/config.rb, line 34 def custom_values instance.custom_values end
Source
# File lib/fontist/config.rb, line 46 def default_value(key) instance.default_value(key) end
Source
# File lib/fontist/config.rb, line 50 def from_file(path) return new unless File.exist?(path) content = File.read(path) from_yaml(content) end
Source
# File lib/fontist/config.rb, line 26 def instance @instance ||= new.tap(&:load) end
Source
# File lib/fontist/config.rb, line 58 def initialize(**attrs) @custom_values = {} super end
              Calls superclass method
              
            
        Source
# File lib/fontist/config.rb, line 38 def set(key, value) instance.set(key, value) end
Public Instance Methods
Source
# File lib/fontist/config.rb, line 90 def default_value(key) default_values[key.to_sym] end
Source
# File lib/fontist/config.rb, line 94 def default_values { fonts_path: Fontist.fontist_path.join("fonts"), open_timeout: 60, read_timeout: 60, google_fonts_key: nil } end
Source
# File lib/fontist/config.rb, line 85 def delete(key) @custom_values.delete(key.to_sym) persist end
Source
# File lib/fontist/config.rb, line 115 def fonts_path=(value) @custom_values[:fonts_path] = File.expand_path(value.to_s) @fonts_path = @custom_values[:fonts_path] end
Source
# File lib/fontist/config.rb, line 111 def load @custom_values = load_config_file end
Source
# File lib/fontist/config.rb, line 101 def persist config_model = self.class.new @custom_values.each do |key, value| config_model.send("#{key}=", value) if config_model.respond_to?("#{key}=") end FileUtils.mkdir_p(File.dirname(Fontist.config_path)) config_model.to_file(Fontist.config_path) end
Source
# File lib/fontist/config.rb, line 71 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) @custom_values[attr] = v send("#{attr}=", v) if respond_to?("#{attr}=") persist end
Source
# File lib/fontist/config.rb, line 120 def to_file(path) File.write(path, to_yaml) end
Source
# File lib/fontist/config.rb, line 63 def values default_values.merge(@custom_values) end