Skip to content

Commit 1919e07

Browse files
committed
added mixin logic, dependencies and readme
1 parent f973a90 commit 1919e07

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<p align="center">
2+
<a href="https://www.typisch-touristik.de">
3+
<img alt="Typisch Touristik" src="https://s3.eu-central-1.amazonaws.com/typischtouristik/logo_typisch-touristik_1200x443.png" width="200">
4+
</a>
5+
</p>
6+
7+
<p align="center">
8+
Mixins (horizontal inheritance) for sails models.
9+
</p>
10+
11+
<p align="center">
12+
<a href="https://travis-ci.org/TypischTouristik/sails-hook-mixins" target="_blank"><img alt="Travis Status" src="https://travis-ci.org/TypischTouristik/sails-hook-mixins.svg"></a>
13+
<a href="https://david-dm.org/TypischTouristik/sails-hook-mixins" target="_blank"><img alt="Dependency Status" src="https://david-dm.org/TypischTouristik/sails-hook-mixins.svg"></a>
14+
<a href="https://github.com/TypischTouristik/sails-hook-mixins/releases"><img alt="Version Status" src="https://badge.fury.io/gh/TypischTouristik%2Fsails-hook-mixins.svg"></a>
15+
</p>
16+
17+
---

index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var deepExtend = require('deep-extend');
2+
3+
module.exports = function(sails) {
4+
5+
return {
6+
initialize: function(done) {
7+
sails.after(['hook:moduleloader:loaded'], function() {
8+
_.each(sails.models, function (model) {
9+
// bind model additional attributes on concrete models and left derived model build from associations
10+
if (!model.globalId || !model.mixins) {
11+
return;
12+
}
13+
14+
_.each(model.mixins, function (name) {
15+
var mixin = require(process.cwd() + '/api/mixins/' + name);
16+
deepExtend(model, mixin);
17+
});
18+
});
19+
20+
done();
21+
});
22+
}
23+
};
24+
25+
};

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"sails": {
1414
"isHook": true
1515
},
16-
"dependencies": {},
16+
"dependencies": {
17+
"deep-extend": "^0.4.1"
18+
},
1719
"repository": {
1820
"type": "git",
1921
"url": "git://github.com/TypischTouristik/sails-hook-mixins.git"
@@ -23,4 +25,4 @@
2325
"mocha": "^3.1.2",
2426
"sails": "^0.12.8"
2527
}
26-
}
28+
}

0 commit comments

Comments
 (0)