Skip to content

Instantly share code, notes, and snippets.

@srdjan
Created March 14, 2012 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srdjan/2039228 to your computer and use it in GitHub Desktop.
Save srdjan/2039228 to your computer and use it in GitHub Desktop.
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