Skip to content

Instantly share code, notes, and snippets.

@sadjow
Last active August 29, 2015 14:08
Show Gist options
  • Save sadjow/fa6d9f89e8d90465306c to your computer and use it in GitHub Desktop.
Save sadjow/fa6d9f89e8d90465306c to your computer and use it in GitHub Desktop.
A simple example of makesure using CoffeeScript
validateUser = makesure ->
@permit "name email" # optional
@attrs("name email").isNot('empty').orSay "can't be empty"
userInput =
name: ""
description: "My description"
admin: true
# Validates a object, with an intrusive attribute.
validateUser userInput, (error, user) ->
# error == {
# error: {
# attrs: {
# name: {
# messages: { "empty": "can't be empty" }
# }
# }
# }
# }
# user == {
# name: '',
# description: 'My description'
# }
@dgmike
Copy link

dgmike commented Nov 6, 2014

The parentesis in makesure are optionals 😆

validateUser = makesure ->
  @permit "name email" # optional
  @attrs("name email").isNot(empty).orSay "can't be empty"

@sadjow
Copy link
Author

sadjow commented Nov 6, 2014

🆒 🎱 !! 😄 good catch @dgmike!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment