From 5f620fb73919a5ac94b2f401e03e7ca42c19e02e Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 12 Aug 2015 16:52:25 -0700 Subject: [PATCH] Config::getSchema - use null to represent inaccessible key path --- spec/config-spec.coffee | 4 ++-- src/config.coffee | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/spec/config-spec.coffee b/spec/config-spec.coffee index 1821b7e01..3b7bd6061 100644 --- a/spec/config-spec.coffee +++ b/spec/config-spec.coffee @@ -1142,8 +1142,8 @@ describe "Config", -> type: 'integer' default: 12 - expect(atom.config.getSchema('foo.baz')).toBe(null) - expect(atom.config.getSchema('foo.bar.anInt.baz')).toBe(false) + expect(atom.config.getSchema('foo.baz')).toEqual {type: 'any'} + expect(atom.config.getSchema('foo.bar.anInt.baz')).toBe(null) it "respects the schema for scoped settings", -> schema = diff --git a/src/config.coffee b/src/config.coffee index f26599a0b..7c6dc8286 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -664,8 +664,8 @@ class Config # * `keyPath` The {String} name of the key. # # Returns an {Object} eg. `{type: 'integer', default: 23, minimum: 1}`. - # Returns `null` when the keyPath has no schema specified. - # Returns `false` when the key-path is not accessible from the root schema. + # Returns `null` when the keyPath has no schema specified, but is accessible + # from the root schema. getSchema: (keyPath) -> keys = splitKeyPath(keyPath) schema = @schema @@ -676,11 +676,11 @@ class Config if isPlainObject(schema.additionalProperties) childSchema = schema.additionalProperties else if schema.additionalProperties is false - return false - else return null + else + return {type: 'any'} else - return false + return null schema = childSchema schema @@ -959,10 +959,9 @@ class Config catch e undefined else - if (schema = @getSchema(keyPath))? + unless (schema = @getSchema(keyPath))? throw new Error("Illegal key path #{keyPath}") if schema is false - value = @constructor.executeSchemaEnforcers(keyPath, value, schema) - value + @constructor.executeSchemaEnforcers(keyPath, value, schema) # When the schema is changed / added, there may be values set in the config # that do not conform to the schema. This will reset make them conform. @@ -1040,6 +1039,10 @@ class Config # order of specification. Then the `*` enforcers will be run, in order of # specification. Config.addSchemaEnforcers + 'any': + coerce: (keyPath, value, schema) -> + value + 'integer': coerce: (keyPath, value, schema) -> value = parseInt(value)