-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added debug adapter to support ember inspector, updated http-mock and…
… pretender
- Loading branch information
Matthew Marcum
committed
Dec 10, 2014
1 parent
b684ece
commit 33dfcc0
Showing
5 changed files
with
91 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import Model from "./model"; | ||
|
||
export default Ember.DataAdapter.extend({ | ||
|
||
detect: function(klass) { | ||
return klass !== Model && Model.detect(klass); | ||
}, | ||
|
||
columnsForType: function( type ) { | ||
var columns = [], | ||
type = type._debugContainerKey.replace( 'model:',''), | ||
record = this.get( 'store' )._cache._getRecords( type ).records[0]; | ||
|
||
if( record ){ | ||
Ember.keys( record.content ).forEach( function( key ){ | ||
columns.push( { name: key, desc: key }); | ||
}); | ||
} | ||
|
||
return columns; | ||
}, | ||
|
||
getRecords: function( type ){ | ||
var type = type._debugContainerKey.replace( 'model:',''); | ||
return this.get( 'store' )._cache._getRecords( type ).records; | ||
}, | ||
|
||
getRecordColumnValues: function( record ){ | ||
var values = {}; | ||
|
||
if( record ){ | ||
Ember.keys( record.content ).forEach( function( key ){ | ||
values[ key ] = Ember.get( record, key ); | ||
}); | ||
} | ||
|
||
return values; | ||
}, | ||
|
||
observeRecord: function( record, recordUpdated ){ | ||
var releaseMethods = Ember.A(), | ||
self = this, | ||
keysToObserve = Ember.keys( record.content ); | ||
|
||
keysToObserve.forEach(function(key) { | ||
var handler = function() { | ||
recordUpdated(self.wrapRecord(record)); | ||
}; | ||
Ember.addObserver(record, key, handler); | ||
releaseMethods.push(function() { | ||
Ember.removeObserver(record, key, handler); | ||
}); | ||
}); | ||
|
||
var release = function() { | ||
releaseMethods.forEach(function(fn) { fn(); } ); | ||
}; | ||
|
||
return release; | ||
} | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
// To use it create some files under `routes/` | ||
// e.g. `server/routes/ember-hamsters.js` | ||
// | ||
// module.exports = function(app) { | ||
// app.get('/ember-hamsters', function(req, res) { | ||
// res.send('hello'); | ||
// }); | ||
// }; | ||
|
||
module.exports = function(app) { | ||
var globSync = require('glob').sync; | ||
var bodyParser = require('body-parser'); | ||
var mocks = globSync('./mocks/**/*.js', { cwd: __dirname }).map(require); | ||
var proxies = globSync('./proxies/**/*.js', { cwd: __dirname }).map(require); | ||
|
||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ | ||
extended: true | ||
})); | ||
// Log proxy requests | ||
var morgan = require('morgan'); | ||
app.use(morgan('dev')); | ||
|
||
mocks.forEach(function(route) { route(app); }); | ||
|
||
// proxy expects a stream, but express will have turned | ||
// the request stream into an object because bodyParser | ||
// has run. We have to convert it back to stream: | ||
// https://github.com/nodejitsu/node-http-proxy/issues/180 | ||
app.use(require('connect-restreamer')()); | ||
proxies.forEach(function(route) { route(app); }); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters