Update config

This commit is contained in:
Garen Torikian
2013-04-30 13:08:58 -07:00
parent 685ec5d8d7
commit 66a80ade30

View File

@@ -88,7 +88,19 @@ class Config
@watchSubscription?.close()
@watchSubscription = null
# Public: Retrieves the setting for the given key.
setDefaults: (keyPath, defaults) ->
keys = keyPath.split('.')
hash = @defaultSettings
for key in keys
hash[key] ?= {}
hash = hash[key]
_.extend hash, defaults
@update()
### Public ###
# Retrieves the setting for the given key.
#
# keyPath - The {String} name of the key to retrieve
#
@@ -98,25 +110,28 @@ class Config
_.valueForKeyPath(@settings, keyPath) ?
_.valueForKeyPath(@defaultSettings, keyPath)
# Public: Retrieves the setting for the given key as an integer number.
# Retrieves the setting for the given key as an integer.
#
# keyPath - The {String} name of the key to retrieve
#
# Returns the value from Atom's default settings, the user's configuration file,
# or `NaN` if the key doesn't exist in either.
getInt: (keyPath, defaultValueWhenFalsy) ->
parseInt(@get(keyPath))
# Public: Retrieves the setting for the given key as a positive integer number.
# Retrieves the setting for the given key as a positive integer.
#
# keyPath - The {String} name of the key to retrieve
# defaultValue - The integer {Number} to fall back to if the value isn't
# positive
#
# Returns the value from Atom's default settings, the user's configuration file,
# or `defaultValue` if the key value isn't greater than zero.
getPositiveInt: (keyPath, defaultValue) ->
Math.max(@getInt(keyPath), 0) or defaultValue
# Public: Sets the value for a configuration setting.
# Sets the value for a configuration setting.
#
# This value is stored in Atom's internal configuration file.
#
@@ -129,17 +144,7 @@ class Config
@update()
value
setDefaults: (keyPath, defaults) ->
keys = keyPath.split('.')
hash = @defaultSettings
for key in keys
hash[key] ?= {}
hash = hash[key]
_.extend hash, defaults
@update()
# Public: Establishes an event listener for a given key.
# Establishes an event listener for a given key.
#
# Whenever the value of the key is changed, a callback is fired.
#
@@ -160,6 +165,18 @@ class Config
callback(value)
subscription
### Internal ###
setDefaults: (keyPath, defaults) ->
keys = keyPath.split('.')
hash = @defaultSettings
for key in keys
hash[key] ?= {}
hash = hash[key]
_.extend hash, defaults
@update()
update: ->
return if @configFileHasErrors
@save()