-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from 90TechSAS/feature/inheritence
add inheritence
- Loading branch information
Showing
18 changed files
with
626 additions
and
21 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//_ = require('lodash'); | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
// istanbul ignore next | ||
|
||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
|
||
// istanbul ignore next | ||
|
||
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
|
||
exports['default'] = Discriminator; | ||
// istanbul ignore next | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
|
||
// istanbul ignore next | ||
|
||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
|
||
// istanbul ignore next | ||
|
||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
|
||
var _ServiceLocator = require('./ServiceLocator'); | ||
|
||
var _ServiceLocator2 = _interopRequireDefault(_ServiceLocator); | ||
|
||
var _SessionManager = require('./SessionManager'); | ||
|
||
var _SessionManager2 = _interopRequireDefault(_SessionManager); | ||
|
||
function Discriminator(Model, type) { | ||
|
||
var Discriminator = (function (_Model) { | ||
_inherits(Discriminator, _Model); | ||
|
||
function Discriminator() { | ||
_classCallCheck(this, Discriminator); | ||
|
||
_get(Object.getPrototypeOf(Discriminator.prototype), 'constructor', this).apply(this, arguments); | ||
} | ||
|
||
_createClass(Discriminator, null, [{ | ||
key: 'type', | ||
get: function get() { | ||
return type; | ||
} | ||
}]); | ||
|
||
return Discriminator; | ||
})(Model); | ||
|
||
return Discriminator; | ||
} | ||
|
||
module.exports = exports['default']; |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
// istanbul ignore next | ||
|
||
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
|
||
// istanbul ignore next | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
|
||
// istanbul ignore next | ||
|
||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
|
||
// istanbul ignore next | ||
|
||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
|
||
var _modelsTstModel4Js = require('./../models/tstModel4.js'); | ||
|
||
var _modelsTstModel4Js2 = _interopRequireDefault(_modelsTstModel4Js); | ||
|
||
var _GenericDao = require('../GenericDao'); | ||
|
||
var _GenericDao2 = _interopRequireDefault(_GenericDao); | ||
|
||
var _Discriminator = require('../Discriminator'); | ||
|
||
var _Discriminator2 = _interopRequireDefault(_Discriminator); | ||
|
||
var D1 = (0, _Discriminator2['default'])(_modelsTstModel4Js2['default'], 'Type1'); | ||
var D2 = (0, _Discriminator2['default'])(_modelsTstModel4Js2['default'], 'Type2'); | ||
|
||
var DAO = (0, _GenericDao2['default'])(_modelsTstModel4Js2['default'], undefined, [D1, D2]); | ||
|
||
var ModelManager4 = (function (_DAO) { | ||
_inherits(ModelManager4, _DAO); | ||
|
||
function ModelManager4() { | ||
_classCallCheck(this, ModelManager4); | ||
|
||
_get(Object.getPrototypeOf(ModelManager4.prototype), 'constructor', this).apply(this, arguments); | ||
} | ||
|
||
return ModelManager4; | ||
})(DAO); | ||
|
||
exports['default'] = ModelManager4; | ||
; | ||
module.exports = exports['default']; |
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,54 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
// istanbul ignore next | ||
|
||
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
|
||
// istanbul ignore next | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
|
||
// istanbul ignore next | ||
|
||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
|
||
// istanbul ignore next | ||
|
||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
|
||
var _ActiveRecord = require('../ActiveRecord'); | ||
|
||
var _ActiveRecord2 = _interopRequireDefault(_ActiveRecord); | ||
|
||
var model = { | ||
|
||
_id: { | ||
type: String, | ||
unique: true | ||
}, | ||
|
||
//private: true | ||
name: String, | ||
|
||
__t: String | ||
}; | ||
|
||
var AR = (0, _ActiveRecord2['default'])(model, 'Model4'); | ||
|
||
var Model4 = (function (_AR) { | ||
_inherits(Model4, _AR); | ||
|
||
function Model4() { | ||
_classCallCheck(this, Model4); | ||
|
||
_get(Object.getPrototypeOf(Model4.prototype), 'constructor', this).apply(this, arguments); | ||
} | ||
|
||
return Model4; | ||
})(AR); | ||
|
||
exports['default'] = Model4; | ||
module.exports = exports['default']; |
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,58 @@ | ||
'use strict'; | ||
|
||
describe('Angular DAO', function () { | ||
|
||
var ModelManager, ModelManager3, httpBackend, $rootScope, $timeout; | ||
|
||
beforeEach(function () { | ||
|
||
module('tstModule', function (ModelManager4Provider) { | ||
ModelManager4Provider.setRootUrl('http://MOCKURL.com/model2'); | ||
ModelManager4Provider.setDiscriminatorUrl('Type1', 'http://fakeurl/type1'); | ||
ModelManager4Provider.setDiscriminatorUrl('Type2', 'http://fakeurl/type2'); | ||
}); | ||
|
||
inject(function (_ModelManager4_, $httpBackend, _$rootScope_, _$timeout_) { | ||
ModelManager4 = _ModelManager4_; | ||
httpBackend = $httpBackend; | ||
$rootScope = _$rootScope_; | ||
$timeout = _$timeout_; | ||
}); | ||
}); | ||
|
||
it('should be possible to instantiate discriminators', function () { | ||
expect(ModelManager4.discriminators.length).toEqual(2); | ||
expect(ModelManager4.discriminators[0].type).toEqual('Type1'); | ||
expect(ModelManager4.discriminators[1].type).toEqual('Type2'); | ||
expect(ModelManager4.discriminators[0].discriminatorUrl).toEqual('http://fakeurl/type1'); | ||
expect(ModelManager4.discriminators[1].discriminatorUrl).toEqual('http://fakeurl/type2'); | ||
}); | ||
|
||
it('should make GET queries on parent url', function () { | ||
httpBackend.expectGET('http://MOCKURL.com/model2').respond(); | ||
ModelManager4.get(); | ||
httpBackend.flush(); | ||
}); | ||
|
||
it('should instanciate discriminators according to __t value', function () { | ||
// TODO : make a GET request, respond with two types, and check their urls | ||
httpBackend.expectGET('http://MOCKURL.com/model2').respond([{ _id: 123, name: 'Type1', __t: 'Type1' }, { _id: 321, name: 'Type2', __t: 'Type2' }]); | ||
|
||
ModelManager4.get().then(function (data) { | ||
expect(data.data[0].rootUrl).toEqual('http://fakeurl/type1'); | ||
expect(data.data[1].rootUrl).toEqual('http://fakeurl/type2'); | ||
}); | ||
httpBackend.flush(); | ||
}); | ||
|
||
it('should make POST queries on correct discriminator URL', function () { | ||
var obj = ModelManager4.createModel({ _id: 123456, name: '12345', __t: 'Type1' }); | ||
obj.name = '23456'; | ||
httpBackend.expectPUT('http://fakeurl/type1/123456', { name: '23456' }).respond(); | ||
obj.save(); | ||
}); | ||
|
||
afterEach(function () { | ||
httpBackend.verifyNoOutstandingExpectation(); | ||
}); | ||
}); |
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,7 +1,7 @@ | ||
{ | ||
"author": "flogou <[email protected]>", | ||
"name": "angular-orm", | ||
"version": "2.0.0-alpha-11", | ||
"version": "2.0.0-alpha-12", | ||
"description": "", | ||
"homepage": "", | ||
"dependencies": { | ||
|
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//_ = require('lodash'); | ||
import ServiceLocator from './ServiceLocator' | ||
import SessionManager from './SessionManager' | ||
|
||
|
||
export default function Discriminator (Model, type) { | ||
|
||
let Discriminator = class extends Model{ | ||
static get type (){ | ||
return type | ||
} | ||
}; | ||
|
||
return Discriminator; | ||
} |
Oops, something went wrong.