Skip to content

Commit e1975b7

Browse files
authored
Merge pull request #29 from BoolJS/develop
Release v0.8.0
2 parents 5b9e7d4 + 414ec38 commit e1975b7

21 files changed

Lines changed: 249 additions & 463 deletions

File tree

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

example

Lines changed: 0 additions & 1 deletion
This file was deleted.

example/.jshintrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"node": true,
3+
"laxcomma": true,
4+
"undef": true,
5+
"strict": true,
6+
"unused": true
7+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
3+
"development": {
4+
"host": "localhost",
5+
"database": "db"
6+
},
7+
8+
"test": {
9+
"host": "localhost",
10+
"database": "db_test"
11+
},
12+
13+
"production": {
14+
"host": "example.com",
15+
"database": "db"
16+
}
17+
18+
}

example/configuration/server.cson

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'host': 'localhost'
2+
'port': 8080
3+
'credentials':
4+
'user': 'example'
5+
'password': 'samplepass'

example/controllers/dog.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
3+
module.exports = function(app){
4+
5+
var Dog = app.dao.Dog
6+
, json = new app.views.Json();
7+
8+
return {
9+
list: function(req, res, next){
10+
var dog = new Dog();
11+
json.promise(dog.list(), res, next);
12+
}
13+
};
14+
15+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
module.exports = function (app) {
4+
const { Dog } = app.dao;
5+
const { promise } = new app.views.Json();
6+
7+
this.list = function (request, response, next) {
8+
var dog = new Dog();
9+
promise(dog.list(), response, next);
10+
};
11+
};

example/dao/dog.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
module.exports = function(app){
4+
5+
var dog = new app.models.Dog();
6+
7+
return {
8+
list: function(){
9+
return dog.list();
10+
}
11+
};
12+
13+
};

example/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
const Bool = require('..');
3+
4+
// Here is where magic happens
5+
module.exports = new Bool('com.example.api').run();

example/models/dog.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict';
2+
3+
const dogs = [];
4+
5+
module.exports = class DogModel {
6+
constructor (app) {
7+
this.Error = app.Error;
8+
}
9+
10+
async list () {
11+
return dogs;
12+
}
13+
14+
async index (id) {
15+
for (var dog in dogs) {
16+
if (dogs[dog].id === id) {
17+
return dog;
18+
}
19+
}
20+
return null;
21+
}
22+
23+
async find (id) {
24+
var index = this.index(id);
25+
if (index === null) {
26+
throw new this.Error(
27+
404, 'dog_not_found', 'The searched dog wasn\'t in the list'
28+
);
29+
}
30+
return dogs[index];
31+
}
32+
33+
async update (id, dog) {
34+
Object.assign(this.find(id), dog);
35+
}
36+
37+
async delete (id) {
38+
var index = this.index(id);
39+
40+
if (index === null) {
41+
throw new this.Error(
42+
404, 'dog_not_found', 'The searched dog wasn\'t in the list'
43+
);
44+
}
45+
46+
dogs.splice(index, 1);
47+
}
48+
};

0 commit comments

Comments
 (0)