Skip to content

Commit 10fb746

Browse files
committed
added: SchemaBuilderEntity.constant()
1 parent 0c6d543 commit 10fb746

7 files changed

Lines changed: 47 additions & 18 deletions

File tree

builders.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ function SchemaBuilderEntity(parent, name, obj, validator, properties) {
9494
this.composes;
9595
this.operations;
9696
this.rules;
97+
this.constants;
9798
this.onDefault;
9899
this.onValidation = validator;
99100
this.onSave;
@@ -274,6 +275,25 @@ SchemaBuilderEntity.prototype.addRule = function(name, value) {
274275
return self;
275276
};
276277

278+
/**
279+
* Add a new constant for the schema
280+
* @param {String} name Constant name, optional.
281+
* @param {Object} value
282+
* @return {SchemaBuilderEntity}
283+
*/
284+
SchemaBuilderEntity.prototype.constant = function(name, value) {
285+
var self = this;
286+
287+
if (value === undefined)
288+
return self.constants ? self.constants[name] : undefined;
289+
290+
if (!self.constants)
291+
self.constants = {};
292+
293+
self.constants[name] = value;
294+
return self;
295+
};
296+
277297
/**
278298
* Add a new transformation for the entity
279299
* @param {String} name Transform name, optional.
@@ -759,6 +779,10 @@ SchemaBuilderEntity.prototype.$make = function(obj) {
759779
return self.rule(name);
760780
};
761781

782+
obj.$constant = function(name) {
783+
return self.constant(name);
784+
};
785+
762786
return obj;
763787
};
764788

@@ -1466,6 +1490,7 @@ SchemaBuilderEntity.prototype.clean = function(m, isCopied) {
14661490
delete model['$validate'];
14671491
delete model['$compose'];
14681492
delete model['$rule'];
1493+
delete model['$constant'];
14691494

14701495
var keys = Object.keys(model);
14711496

changes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
IN DEVELOPMENT ======= 1.7.2 (HOTFIX)
22

33
- added: Array.prototype.extend(obj, [rewrite])
4+
- added: SchemaBuilderEntity->constant(name, [value])
45
- added: Utils.minifyHTML(value);
56
- added: Utils.minifyScript(value);
67
- added: Utils.minifyStyle(value);

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ function Framework() {
162162

163163
this.id = null;
164164
this.version = 1720;
165-
this.version_header = '1.7.2 (build: 7)';
165+
this.version_header = '1.7.2 (build: 8)';
166166

167167
var version = process.version.toString().replace('v', '').replace(/\./g, '');
168168

minify/merged/total.js

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

minify/total.js/builders.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

minify/total.js/index.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/test-builders.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,9 @@ function test_Schema() {
222222
assert.ok(value === 3, 'schema - operation advanced 2');
223223
}).operation('test2', function(err, value) {
224224
assert.ok(value === 3, 'schema - operation advanced 3');
225-
});
225+
}).constant('test', true);
226+
227+
assert.ok(SCHEMA('default', '2').constant('test') === true, 'schema - constant');
226228

227229
builders.schema('validator', {
228230
name: 'string',

0 commit comments

Comments
 (0)