Class: Skylight::Core::UserConfig
- Inherits:
-
Object
- Object
- Skylight::Core::UserConfig
- Defined in:
- lib/skylight/core/user_config.rb
Instance Attribute Summary collapse
-
#disable_dev_warning ⇒ Object
Returns the value of attribute disable_dev_warning.
-
#disable_env_warning ⇒ Object
Returns the value of attribute disable_env_warning.
Instance Method Summary collapse
- #disable_dev_warning? ⇒ Boolean
- #disable_env_warning? ⇒ Boolean
- #file_path ⇒ Object
-
#initialize(config) ⇒ UserConfig
constructor
A new instance of UserConfig.
- #reload ⇒ Object
- #save ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(config) ⇒ UserConfig
Returns a new instance of UserConfig.
9 10 11 12 13 |
# File 'lib/skylight/core/user_config.rb', line 9 def initialize(config) @config = config @file_path = nil reload end |
Instance Attribute Details
#disable_dev_warning ⇒ Object
Returns the value of attribute disable_dev_warning.
7 8 9 |
# File 'lib/skylight/core/user_config.rb', line 7 def disable_dev_warning @disable_dev_warning end |
#disable_env_warning ⇒ Object
Returns the value of attribute disable_env_warning.
7 8 9 |
# File 'lib/skylight/core/user_config.rb', line 7 def disable_env_warning @disable_env_warning end |
Instance Method Details
#disable_dev_warning? ⇒ Boolean
31 32 33 |
# File 'lib/skylight/core/user_config.rb', line 31 def disable_dev_warning? disable_dev_warning || ENV['SKYLIGHT_DISABLE_DEV_WARNING'] =~ /^true$/i end |
#disable_env_warning? ⇒ Boolean
35 36 37 |
# File 'lib/skylight/core/user_config.rb', line 35 def disable_env_warning? disable_env_warning end |
#file_path ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/skylight/core/user_config.rb', line 15 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.("~#{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.(config_path) end |
#reload ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/skylight/core/user_config.rb', line 39 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 ⇒ Object
47 48 49 50 51 52 |
# File 'lib/skylight/core/user_config.rb', line 47 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 ⇒ Object
54 55 56 57 58 59 |
# File 'lib/skylight/core/user_config.rb', line 54 def to_hash { 'disable_dev_warning' => disable_dev_warning, 'disable_env_warning' => disable_env_warning } end |