Created
March 14, 2012 20:20
-
-
Save srdjan/2039228 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Entity extends Batman.Model | |
@field: (name, options) -> | |
@fields ?= {} | |
@fields[name] = options || {} | |
constructor: (attributes) -> | |
@attributes = {} | |
for name, options of @constructor.fields | |
@attributes['encode'] = true | |
@attributes[name] = | |
if attributes?[name] | |
attributes?[name] | |
else if options.default | |
options.default | |
else if options.encode | |
options.encode | |
# Getters and setters | |
get: (name) => | |
#redirect to Batman.Model | |
set: (name, value) => | |
#redirect to Batman.Model | |
#... | |
############################################### | |
class Todo extends Entity | |
@field 'body', default: '' | |
@field 'isDone', default: false | |
@field 'temp', default: "local helper", encode: false | |
# for more see here: http://almostobsolete.net/declarative-models-in-coffeescript.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment