lib/discourse_theme/config.rb in discourse_theme-0.1.8 vs lib/discourse_theme/config.rb in discourse_theme-0.2.0

- old
+ new

@@ -5,25 +5,33 @@ @config = config @path = path end def api_key - safe_config["api_key"] + search_api_key(url) || safe_config["api_key"] end def api_key=(val) - set("api_key", val) + set_api_key(url, val) end def url safe_config["url"] end def url=(val) set("url", val) end + def theme_id + safe_config["theme_id"].to_i + end + + def theme_id=(theme_id) + set("theme_id", theme_id.to_i) + end + protected def set(name, val) hash = @config.raw_config[@path] ||= {} hash[name] = val @@ -37,10 +45,22 @@ config else {} end end + + def search_api_key(url) + hash = @config.raw_config["api_keys"] + hash[url] if hash + end + + def set_api_key(url, api_key) + hash = @config.raw_config["api_keys"] ||= {} + hash[url] = api_key + @config.save + api_key + end end attr_reader :raw_config, :filename def initialize(filename) @@ -55,16 +75,9 @@ $stderr.puts "ERROR: #{@filename} contains invalid config, resetting" end else @raw_config = {} end - end - - def set(path, url:, api_key:) - @raw_config[path] = { - "url" => url, - "api_key" => api_key - } end def save File.write(@filename, @raw_config.to_yaml) end