Class: Depot::Settings
- Inherits:
-
Object
- Object
- Depot::Settings
- Defined in:
- lib/depot/settings.rb
Constant Summary collapse
- DEFAULTS =
{ "warning_verbosity" => "normal", "theme" => "system", "default_install_location" => "user", "sandbox_preference" => "ask", "sandbox_profile" => "balanced", "sandbox_home_access" => "documents", "sandbox_network" => true, "desktop_integration" => true, "updates_enabled" => true }.freeze
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path = Paths.settings_path) ⇒ Settings
constructor
A new instance of Settings.
- #load ⇒ Object
- #save(values) ⇒ Object
Constructor Details
#initialize(path = Paths.settings_path) ⇒ Settings
Returns a new instance of Settings.
23 24 25 |
# File 'lib/depot/settings.rb', line 23 def initialize(path = Paths.settings_path) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
21 22 23 |
# File 'lib/depot/settings.rb', line 21 def path @path end |
Instance Method Details
#load ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/depot/settings.rb', line 27 def load return DEFAULTS.dup unless File.exist?(path) parsed = JSON.parse(File.read(path)) DEFAULTS.merge(parsed) rescue JSON::ParserError DEFAULTS.dup end |
#save(values) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/depot/settings.rb', line 36 def save(values) FileUtils.mkdir_p(File.dirname(path)) normalized = DEFAULTS.merge(values.transform_keys(&:to_s)) File.write(path, JSON.pretty_generate(normalized) + "\n") normalized end |