mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 15:37:46 +03:00
Don't write config
defaults out to config.json
This commit is contained in:
parent
dec3ab7873
commit
d509093076
@ -1,3 +1,5 @@
|
||||
fs = require 'fs'
|
||||
|
||||
describe "Config", ->
|
||||
describe ".get(keyPath) and .set(keyPath, value)", ->
|
||||
it "allows a key path's value to be read and written", ->
|
||||
@ -15,14 +17,33 @@ describe "Config", ->
|
||||
expect(config.save).toHaveBeenCalled()
|
||||
expect(observeHandler).toHaveBeenCalledWith 42
|
||||
|
||||
describe ".save()", ->
|
||||
beforeEach ->
|
||||
spyOn(fs, 'write')
|
||||
jasmine.unspy config, 'save'
|
||||
|
||||
it "writes any non-default properties to the config.json in the user's .atom directory", ->
|
||||
config.set("a.b.c", 1)
|
||||
config.set("a.b.d", 2)
|
||||
config.set("x.y.z", 3)
|
||||
config.setDefaults("a.b", e: 4, f: 5)
|
||||
|
||||
config.save()
|
||||
|
||||
writtenConfig = JSON.parse(fs.write.argsForCall[0][1])
|
||||
expect(writtenConfig).toEqual config.settings
|
||||
|
||||
describe ".setDefaults(keyPath, defaults)", ->
|
||||
it "assigns any previously-unassigned keys to the object at the key path", ->
|
||||
config.set("foo.bar.baz", a: 1)
|
||||
config.setDefaults("foo.bar.baz", a: 2, b: 3, c: 4)
|
||||
expect(config.get("foo.bar.baz")).toEqual(a: 1, b: 3, c: 4)
|
||||
expect(config.get("foo.bar.baz.a")).toBe 1
|
||||
expect(config.get("foo.bar.baz.b")).toBe 3
|
||||
expect(config.get("foo.bar.baz.c")).toBe 4
|
||||
|
||||
config.setDefaults("foo.quux", x: 0, y: 1)
|
||||
expect(config.get("foo.quux")).toEqual(x: 0, y: 1)
|
||||
expect(config.get("foo.quux.x")).toBe 0
|
||||
expect(config.get("foo.quux.y")).toBe 1
|
||||
|
||||
describe ".update()", ->
|
||||
it "updates observers if a value is mutated without the use of .set", ->
|
||||
|
@ -22,12 +22,14 @@ class Config
|
||||
configDirPath: configDirPath
|
||||
themeDirPaths: [userThemesDirPath, bundledThemesDirPath]
|
||||
packageDirPaths: [userPackagesDirPath, bundledVendorPackagesDirPath, bundledPackagesDirPath]
|
||||
defaultSettings: null
|
||||
settings: null
|
||||
|
||||
constructor: ->
|
||||
@settings =
|
||||
@defaultSettings =
|
||||
core: _.clone(require('root-view').configDefaults)
|
||||
editor: _.clone(require('editor').configDefaults)
|
||||
@settings = {}
|
||||
|
||||
load: ->
|
||||
@loadUserConfig()
|
||||
@ -41,7 +43,8 @@ class Config
|
||||
_.extend(@settings, userConfig)
|
||||
|
||||
get: (keyPath) ->
|
||||
_.valueForKeyPath(@settings, keyPath)
|
||||
_.valueForKeyPath(@settings, keyPath) ?
|
||||
_.valueForKeyPath(@defaultSettings, keyPath)
|
||||
|
||||
set: (keyPath, value) ->
|
||||
keys = keyPath.split('.')
|
||||
@ -57,12 +60,12 @@ class Config
|
||||
|
||||
setDefaults: (keyPath, defaults) ->
|
||||
keys = keyPath.split('.')
|
||||
hash = @settings
|
||||
hash = @defaultSettings
|
||||
for key in keys
|
||||
hash[key] ?= {}
|
||||
hash = hash[key]
|
||||
|
||||
_.defaults hash, defaults
|
||||
_.extend hash, defaults
|
||||
@update()
|
||||
|
||||
observe: (keyPath, callback) ->
|
||||
|
Loading…
Reference in New Issue
Block a user