Skip to content

Commit

Permalink
V3.0.0 (#16)
Browse files Browse the repository at this point in the history
* 3.0.0
  • Loading branch information
kimung authored Jan 10, 2018
1 parent 78e3f9e commit 3676c37
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 53 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
language: node_js
node_js:
- "node"
- "6.4.0"
script:
- npm test
- npm run coveralls
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## 3.0.0 - 2018-01-10
### Changed
- use es6 syntax
- replace provider instantiation with `Object.create` by `new` + spread (`...`) operator

## 2.0.3 - 2018-01-06
### Changed
- update README
Expand Down
4 changes: 2 additions & 2 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

'use strict';

var errors = require('@rduk/errors');
const errors = require('@rduk/errors');

var BaseProvider = function(config, section) {
const BaseProvider = function(config, section) {
if (!config || !config.name) {
errors.throwArgumentError('config', config);
}
Expand Down
19 changes: 9 additions & 10 deletions lib/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

'use strict';

var errors = require('@rduk/errors');
var configuration = require('@rduk/configuration');
var Section = require('./section');
const errors = require('@rduk/errors');
const configuration = require('@rduk/configuration');
const Section = require('./section');

module.exports = function(name, base, defaultConfig) {
if (!name || typeof name !== 'string' || name.length === 0) {
Expand All @@ -37,9 +37,9 @@ module.exports = function(name, base, defaultConfig) {
errors.throwArgumentError('base', base);
}

var section, instance;
let section, instance;

var getSection = function() {
let getSection = function() {
if (!section) {
section = configuration.load().getSection(name, Section, !!defaultConfig);
}
Expand All @@ -51,9 +51,8 @@ module.exports = function(name, base, defaultConfig) {
return section;
};

var create = function(provider, options) {
var obj = Object.create(provider.prototype);
provider.apply(obj, [options, section]);
let create = function(Provider, options) {
let obj = new Provider(...[options, section]);

if (!(obj instanceof base)) {
errors.throwConfigurationError('invalid provider type');
Expand All @@ -73,8 +72,8 @@ module.exports = function(name, base, defaultConfig) {
return instance;
},
get: function(name) {
var section = getSection();
var options = section.get(name);
let section = getSection();
let options = section.get(name);

return create(options.type, options, section);
}
Expand Down
62 changes: 32 additions & 30 deletions lib/section.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,48 @@

'use strict';

var _ = require('lodash');
var errors = require('@rduk/errors');
var type = require('@rduk/configuration/lib/sections/field/type');
const _ = require('lodash');
const errors = require('@rduk/errors');
const type = require('@rduk/configuration/lib/sections/field/type');

var ProviderSection = function(section) {
if (!section) {
errors.throwArgumentNullError('section');
}
class ProviderSection {
constructor(section) {
if (!section) {
errors.throwArgumentNullError('section');
}

if (!section.hasOwnProperty('default')) {
errors.throwConfigurationError('default property not set.');
}
if (!section.hasOwnProperty('default')) {
errors.throwConfigurationError('default property not set.');
}

if (!section.hasOwnProperty('providers') || !Array.isArray(section.providers)) {
errors.throwConfigurationError('invalid providers section.');
}
if (!section.hasOwnProperty('providers') || !Array.isArray(section.providers)) {
errors.throwConfigurationError('invalid providers section.');
}

this.section = section;
this.section = section;

var providers = {};
var providers = {};

this.get = function(name) {
if (!name) {
name = section.default;
}
this.get = function(name) {
if (!name) {
name = section.default;
}

if (!providers.hasOwnProperty(name)) {
var provider = _.filter(section.providers, function(provider) { return provider.name === name; })[0];
if (!providers.hasOwnProperty(name)) {
var provider = _.filter(section.providers, function(provider) { return provider.name === name; })[0];

if (!provider) {
errors.throwConfigurationError('provider "' + name + '" not found.');
}
if (!provider) {
errors.throwConfigurationError('provider "' + name + '" not found.');
}

provider.type = type.load(provider.type);
provider.type = type.load(provider.type);

providers[name] = provider;
}
providers[name] = provider;
}

return providers[name];
};
};
return providers[name];
};
}
}

module.exports = ProviderSection;
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
{
"name": "@rduk/provider",
"version": "2.0.3",
"version": "3.0.0",
"description": "Easily add providers to your Node.js app",
"engines": {
"node": ">=6.4.0"
},
"main": "lib/factory.js",
"scripts": {
"pretest": "cp ./spec/resources/config*.yml .",
"test": "istanbul cover node_modules/jasmine/bin/jasmine.js --report cobertura",
"posttest": "rm -rf ./config*yml && istanbul report && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
"posttest": "rm -rf ./config*yml && istanbul report",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 3676c37

Please sign in to comment.