mirror of
https://github.com/atom/atom.git
synced 2026-01-22 13:28:01 -05:00
Add an object filter
This commit is contained in:
@@ -576,3 +576,29 @@ describe "Config", ->
|
||||
expect(atom.config.set('foo.bar.aString', 123)).toBe false
|
||||
expect(atom.config.get('foo.bar.aString')).toBe 'ok'
|
||||
|
||||
describe 'when the value has an "object" type', ->
|
||||
beforeEach ->
|
||||
schema =
|
||||
type: 'object'
|
||||
properties:
|
||||
anInt:
|
||||
type: 'integer'
|
||||
default: 12
|
||||
nestedObject:
|
||||
type: 'object'
|
||||
properties:
|
||||
nestedBool:
|
||||
type: 'boolean'
|
||||
default: false
|
||||
atom.config.setSchema('foo.bar', schema)
|
||||
|
||||
it 'converts and validates all the children', ->
|
||||
atom.config.set 'foo.bar',
|
||||
anInt: '23'
|
||||
nestedObject:
|
||||
nestedBool: 't'
|
||||
expect(atom.config.get('foo.bar')).toEqual
|
||||
anInt: 23
|
||||
nestedObject:
|
||||
nestedBool: true
|
||||
|
||||
|
||||
@@ -425,3 +425,10 @@ Config.addTypeFilters
|
||||
coercion: (value, schema) ->
|
||||
throw new Error() unless value == null
|
||||
value
|
||||
|
||||
'object':
|
||||
typeCheck: (value, schema) ->
|
||||
return value unless schema.properties?
|
||||
for prop, childSchema of schema.properties
|
||||
value[prop] = @executeTypeFilters(value[prop], childSchema) if prop of value
|
||||
value
|
||||
|
||||
Reference in New Issue
Block a user