class Skylight::Core::UserConfig

Attributes

disable_dev_warning[RW]
disable_env_warning[RW]

Public Class Methods

new(config) click to toggle source
# File lib/skylight/core/user_config.rb, line 8
def initialize(config)
  @config = config
  @file_path = nil
  reload
end

Public Instance Methods

disable_dev_warning?() click to toggle source
# File lib/skylight/core/user_config.rb, line 30
def disable_dev_warning?
  disable_dev_warning || ENV["SKYLIGHT_DISABLE_DEV_WARNING"] =~ /^true$/i
end
disable_env_warning?() click to toggle source
# File lib/skylight/core/user_config.rb, line 34
def disable_env_warning?
  disable_env_warning
end
file_path() click to toggle source
# File lib/skylight/core/user_config.rb, line 14
def file_path
  return @file_path if @file_path

  config_path = @config[:user_config_path] || begin
    require "etc"
    home_dir = ENV["HOME"] || Etc.getpwuid.dir || (ENV["USER"] && File.expand_path("~#{ENV['USER']}"))
    if home_dir
      File.join(home_dir, ".skylight")
    else
      raise ConfigError, "The Skylight `user_config_path` must be defined since the home directory cannot be inferred"
    end
  end

  @file_path = File.expand_path(config_path)
end
reload() click to toggle source
# File lib/skylight/core/user_config.rb, line 38
def reload
  config = File.exist?(file_path) ? YAML.load_file(file_path) : false
  return unless config

  self.disable_dev_warning = !!config["disable_dev_warning"]
  self.disable_env_warning = !!config["disable_env_warning"]
end
save() click to toggle source
# File lib/skylight/core/user_config.rb, line 46
def save
  FileUtils.mkdir_p(File.dirname(file_path))
  File.open(file_path, "w") do |f|
    f.puts YAML.dump(to_hash)
  end
end
to_hash() click to toggle source
# File lib/skylight/core/user_config.rb, line 53
def to_hash
  {
    "disable_dev_warning" => disable_dev_warning,
    "disable_env_warning" => disable_env_warning
  }
end