class DiscourseTheme::Config::PathSetting

Public Class Methods

new(config, path) click to toggle source
# File lib/discourse_theme/config.rb, line 5
def initialize(config, path)
  @config = config
  @path = path
end

Public Instance Methods

api_key() click to toggle source
# File lib/discourse_theme/config.rb, line 10
def api_key
  search_api_key(url) || safe_config["api_key"]
end
api_key=(val) click to toggle source
# File lib/discourse_theme/config.rb, line 14
def api_key=(val)
  set_api_key(url, val)
end
components() click to toggle source
# File lib/discourse_theme/config.rb, line 34
def components
  safe_config["components"]
end
components=(val) click to toggle source
# File lib/discourse_theme/config.rb, line 38
def components=(val)
  set("components", val)
end
theme_id() click to toggle source
# File lib/discourse_theme/config.rb, line 26
def theme_id
  safe_config["theme_id"].to_i
end
theme_id=(theme_id) click to toggle source
# File lib/discourse_theme/config.rb, line 30
def theme_id=(theme_id)
  set("theme_id", theme_id.to_i)
end
url() click to toggle source
# File lib/discourse_theme/config.rb, line 18
def url
  safe_config["url"]
end
url=(val) click to toggle source
# File lib/discourse_theme/config.rb, line 22
def url=(val)
  set("url", val)
end

Protected Instance Methods

safe_config() click to toggle source
# File lib/discourse_theme/config.rb, line 51
def safe_config
  config = @config.raw_config[@path]
  if Hash === config
    config
  else
    {}
  end
end
search_api_key(url) click to toggle source
# File lib/discourse_theme/config.rb, line 60
def search_api_key(url)
  hash = @config.raw_config["api_keys"]
  hash[url] if hash
end
set(name, val) click to toggle source
# File lib/discourse_theme/config.rb, line 44
def set(name, val)
  hash = @config.raw_config[@path] ||= {}
  hash[name] = val
  @config.save
  val
end
set_api_key(url, api_key) click to toggle source
# File lib/discourse_theme/config.rb, line 65
def set_api_key(url, api_key)
  hash = @config.raw_config["api_keys"] ||= {}
  hash[url] = api_key
  @config.save
  api_key
end