Add Config::getDefault(keyPath)

This commit is contained in:
Kevin Sawicki 2014-04-17 10:08:27 -07:00
parent 37d2e00f4e
commit 20c3ca21e3
2 changed files with 26 additions and 0 deletions

View File

@ -45,6 +45,23 @@ describe "Config", ->
atom.config.set('foo.changes', 1)
expect(atom.config.settings.foo).toEqual {}
describe ".getDefault(keyPath)", ->
it "returns the default value", ->
atom.config.setDefaults("foo", same: 1, changes: 1)
expect(atom.config.getDefault('foo.same')).toBe 1
expect(atom.config.getDefault('foo.changes')).toBe 1
atom.config.set('foo.same', 2)
atom.config.set('foo.changes', 3)
expect(atom.config.getDefault('foo.same')).toBe 1
expect(atom.config.getDefault('foo.changes')).toBe 1
it "returns a clone of the default value", ->
initialDefaultValue = [1, 2, 3]
atom.config.setDefaults("foo", bar: initialDefaultValue)
expect(atom.config.getDefault('foo.bar')).toEqual initialDefaultValue
expect(atom.config.getDefault('foo.bar')).not.toBe initialDefaultValue
describe ".toggle(keyPath)", ->
it "negates the boolean value of the current key path value", ->
atom.config.set('foo.a', 1)

View File

@ -158,6 +158,15 @@ class Config
restoreDefault: (keyPath) ->
@set(keyPath, _.valueForKeyPath(@defaultSettings, keyPath))
# Public: Get the default value of the key path.
#
# keyPath - The {String} name of the key.
#
# Returns the default value.
getDefault: (keyPath) ->
value = _.valueForKeyPath(@defaultSettings, keyPath)
_.deepClone(value)
# Public: Push the value to the array at the key path.
#
# keyPath - The {String} key path.