Support arrays

This commit is contained in:
Ben Ogle 2014-09-23 18:27:24 -07:00
parent 2526ba0efb
commit 409b5536e1
2 changed files with 23 additions and 1 deletions

View File

@ -602,3 +602,15 @@ describe "Config", ->
nestedObject:
nestedBool: true
describe 'when the value has an "array" type', ->
beforeEach ->
schema =
type: 'array'
default: [1, 2, 3]
items:
type: 'integer'
atom.config.setSchema('foo.bar', schema)
it 'converts an array of strings to an array of ints', ->
atom.config.set 'foo.bar', ['2', '3', '4']
expect(atom.config.get('foo.bar')).toEqual [2, 3, 4]

View File

@ -427,8 +427,18 @@ Config.addTypeFilters
value
'object':
typeCheck: (value, schema) ->
coercion: (value, schema) ->
throw new Error() if typeof value isnt 'object'
return value unless schema.properties?
for prop, childSchema of schema.properties
value[prop] = @executeTypeFilters(value[prop], childSchema) if prop of value
value
'array':
coercion: (value, schema) ->
throw new Error() unless Array.isArray(value)
itemSchema = schema.items
if itemSchema?
@executeTypeFilters(item, itemSchema) for item in value
else
value