Reset all user config values when the schema changes.

This commit is contained in:
Ben Ogle
2015-01-27 15:09:19 -08:00
parent d2f485a1ab
commit 79094ee889
2 changed files with 53 additions and 0 deletions

View File

@@ -797,6 +797,7 @@ class Config
_.extend rootSchema, schema
@setDefaults(keyPath, @extractDefaultsFromSchema(schema))
@setScopedDefaultsFromSchema(keyPath, schema)
@resetForSchemaChange()
load: ->
@initializeConfigDirectory()
@@ -1002,6 +1003,20 @@ class Config
value = @constructor.executeSchemaEnforcers(keyPath, value, schema) if schema = @getSchema(keyPath)
value
# When the schema is changed / added, there may be values set in the config
# that do not conform to the config. This will reset make them conform.
resetForSchemaChange: (source=@getUserConfigPath()) ->
settings = @settings
@settings = null
@set(null, settings, {save: false})
priority = @priorityForSource(source)
selectorsAndSettings = @scopedSettingsStore.propertiesForSource(source)
@scopedSettingsStore.removePropertiesForSource(source)
for scopeSelector, settings of selectorsAndSettings
@set(null, settings, {scopeSelector, source, priority, save: false}) if settings?
return
###
Section: Private Scoped Settings
###