(function(){var isUnderscoreDefined,indexOf=[].indexOf||function(item){for(var i=0,l=this.length;i=0){throw"Duplicate identifier : "+identifier}else{ids.push(identifier)}methods={id:function(){return identifier},key:function(){return enumName},describe:function(){var prop;return enumName+":"+identifier+(valueIsObject?" {"+function(){var ref,results;ref=_.extend(descriptor,valueProto);results=[];for(enumName in ref){prop=ref[enumName];if(!_.isFunction(prop)){results.push(enumName+":"+prop)}}return results}()+"}":"")}};testReserved=function(object){var field,results;results=[];for(field in object){if(indexOf.call(_.keys(_.extend({},methods,enumerationProto)),field)>=0){throw"Reserved field "+field+" cannot be passed as enum property"}}return results};testReserved(valueProto);prototype=baseCreate(enumerationProto);_.extend(prototype,methods,valueProto);properties={};defineReadOnlyProperty=function(key0,value0){return properties[key0]=value0};if(_.isObject(descriptor)){testReserved(descriptor);if(descriptor._id==null){throw"field '_id' must be defined when passing object as enum constant"}if(_.isObject(descriptor._id)){throw"_id descriptor field must be of type string or number"}for(key1 in descriptor){val1=descriptor[key1];if(key1!=="_id"){defineReadOnlyProperty(key1,val1)}}}return freezeObject(createObject(prototype,properties))};function Enumeration(enumType,enumValues,proto){var idToKeyMap,ids,key,self,val,writeConstant;if(proto==null){proto={}}idToKeyMap=_.object(_.map(enumValues,function(key,value){return[key._id||key,value]}));self=function(){return self.pretty()};ids=[];if(!_.isString(enumType)){throw"missing or bad enumType value : must be a string"}if(!_.isObject(enumValues)||_.isArray(enumValues)){throw"missing or bad enumValues : must be an object"}if(indexOf.call(enumTypes,enumType)>=0){throw enumType+" already exists!"}else{if(function(){var i,len,ref,results;ref=_.keys(enumValues);results=[];for(i=0,len=ref.length;i0){throw"Cannot have enum constant as one amongst reserved enumeration property [pretty,from]"}}self.prototype={type:function(){return enumType}};writeConstant=function(_this){return function(descriptor,key){return self[key]=Enumeration.constant(key,descriptor,proto,ids,self.prototype)}}(this);for(key in enumValues){val=enumValues[key];writeConstant(val,key)}defineNonEnumerableProperty(self,"pretty",function(){return enumType+":"+function(){var results;results=[];for(key in enumValues){results.push("\n "+self[key].describe())}return results}()});defineNonEnumerableProperty(self,"from",function(identifier,throwOnFailure){if(throwOnFailure==null){throwOnFailure=false}return self[idToKeyMap[identifier]]||function(){if(throwOnFailure){throw"identifier "+identifier+" does not match any"}}()});freezeObject(self);enumTypes.push(enumType);return self}return Enumeration}();return Enumeration})}).call(this);