src/joosy/extensions/resources/base.coffee in joosy-1.2.0.alpha.38 vs src/joosy/extensions/resources/base.coffee in joosy-1.2.0.alpha.41

- old
+ new

@@ -211,13 +211,15 @@ # # @param [String] path Attribute name to get. Can contain dots to get inline Objects values # @return [mixed] # __get: (path) -> - target = @__callTarget path + target = @__callTarget path, true - if target[0] instanceof Joosy.Resources.Base + if !target + return undefined + else if target[0] instanceof Joosy.Resources.Base return target[0](target[1]) else return target[0][target[1]] # @@ -239,18 +241,21 @@ # # Locates the actual instance of attribute path `foo.bar` from get/set # # @param [String] path Path to the attribute (`foo.bar`) + # @param [Boolean] safe Indicates whether nested hashes should not be automatically created when they don't exist # @return [Array] Instance of object containing last step of path and keyword for required field # - __callTarget: (path) -> + __callTarget: (path, safe=false) -> if path.has(/\./) && !@data[path]? path = path.split '.' keyword = path.pop() target = @data for part in path + return false if safe && !target[part]? + target[part] ||= {} if target instanceof Joosy.Resources.Base target = target(part) else target = target[part]