Skip to content

Commit

Permalink
Made objectify idempotent.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitar committed Apr 8, 2014
1 parent 1f6aaa7 commit 09db486
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,16 @@ class globals.Document

if field.isArray
throw new Error "Document does not match schema, not an array" unless _.isArray obj[name]
obj[name] = _.map obj[name], (o) => new field.targetDocument o
obj[name] = _.map obj[name], (o) =>
if o instanceof field.targetDocument
o
else
new field.targetDocument o
else
throw new Error "Document does not match schema, ancestorArray does not match: #{ field.ancestorArray } vs. #{ ancestorArray }" if field.ancestorArray isnt ancestorArray
throw new Error "Document does not match schema, not a plain object" unless isPlainObject obj[name]
obj[name] = new field.targetDocument obj[name]
if obj[name] not instanceof field.targetDocument
obj[name] = new field.targetDocument obj[name]

else if isPlainObject field
if _.isArray obj[name]
Expand Down

0 comments on commit 09db486

Please sign in to comment.