Permalink
Browse files

Added some controller validations

  • Loading branch information...
fk1blow committed May 28, 2011
1 parent 7e5c0e1 commit d1d3a2026ebba5d73b695c6d0633cfab0a786a8c
Showing with 42 additions and 0 deletions.
  1. +42 −0 lib/Controller/Validator.js
@@ -0,0 +1,42 @@
+var Validator = Klass({
+ statics: {
+ rules: {
+ 'controller_name': /[a-z]+/,
+ 'controller_object': /^[A-Z]{1}[a-zA-Z]+/,
+ 'action_name': /[a-z]+/
+ },
+
+ controllerObject: function(val) {
+ return this.rules.controller_object.test(val);
+ },
+
+ controllerName: function(val) {
+ return this.rules.controller_name.test(val);
+ },
+
+ actionName: function(val) {
+ return this.rules.action_name.test(val);
+ }
+ }
+});
+
+
+var ControllerValidator = Klass({
+ statics: {
+ aliases: {
+ 'c_n': 'controllerName',
+ 'c_o': 'controllerObject',
+ 'a_n': 'actionName'
+ },
+
+ validate: function(what, on) {
+ var m = this.aliases[what];
+ if(m) {
+ return Validator[m].call(Validator, on);
+ }
+ }
+ }
+});
+
+
+module.exports = ControllerValidator;

0 comments on commit d1d3a20

Please sign in to comment.