Permalink
Browse files

applies changes in crank.json file

  • Loading branch information...
1 parent 09a8022 commit 810e92c8f1035e17c12c658a3a718b01700856c1 @drewfish committed Apr 8, 2012
Showing with 40 additions and 4 deletions.
  1. +40 −4 lib/crank.js
View
@@ -46,9 +46,45 @@ SCMS.svn = require(libpath.join(__dirname, 'scm-svn.js'));
//------------------------------------------------------------------------
// utility functions
-// merges changes into dest
-function objectMerge(dest, changes) {
- // TODO
+// returns a merge of the two objects
+// values in "b" take precedence over values in "a"
+function objectMerge(a, b) {
+ var key, keys,
+ out;
+ if (a && !b) {
+ return a;
+ }
+ if (!a && b) {
+ return b;
+ }
+ if (!a && !b) {
+ return b;
+ }
+ if (typeof a !== typeof b) {
+ return b;
+ }
+ if ('object' === typeof a) {
+ keys = {};
+ for (key in a) {
+ if (a.hasOwnProperty(key)) {
+ keys[key] = true;
+ }
+ }
+ for (key in b) {
+ if (b.hasOwnProperty(key)) {
+ keys[key] = true;
+ }
+ }
+ out = {};
+ for (key in keys) {
+ if (keys.hasOwnProperty(key)) {
+ out[key] = objectMerge(a[key], b[key]);
+ }
+ }
+ return out;
+ }
+ // FUTURE: merge arrays?
+ return b;
}
@@ -89,7 +125,7 @@ function Base(options) {
// config file overlays defaults
configfile = options.config || 'crank.json';
- objectMerge(this.config, this.fileReadJSON(configfile));
+ this.config = objectMerge(this.config, this.fileReadJSON(configfile));
}

0 comments on commit 810e92c

Please sign in to comment.