Skip to content

Instantly share code, notes, and snippets.

@ayosec
Created May 13, 2012 17:58
Show Gist options
  • Select an option

  • Save ayosec/2689509 to your computer and use it in GitHub Desktop.

Select an option

Save ayosec/2689509 to your computer and use it in GitHub Desktop.
POC: Models in Scala
// Source
class User extends BaseModel {
fields {
name [String]
password [String]
email [String]
age [Int]
}
def customMethod = { /* .... */ }
}
// Expected result
class User extends BaseModel {
override val model = User
// readField and writeField are defined in BaseModel
def name = readField[String]("name")
def name_=(value: String) = writeField("name", value)
def password = readField[String]("password")
def password_=(value: String) = writeField("password", value)
def email = readField[String]("email")
def email_=(value: String) = writeField("email", value)
def age = readField[Int]("age")
def age_=(value: Int) = writeField("age", value)
def customMethod = { /* .... */ }
}
object User extends CompanionBaseModel {
override val modelName = "User"
override val collectionName = "users"
override val fields = List(
Field[String]("name"),
Field[String]("password"),
Field[String]("email"),
Field[Int]("age")
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment