Created
December 21, 2012 18:10
-
-
Save anonymous/4354623 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 AddUserParams < OpenStruct | |
include DataMapper::Validations | |
validates_with_method :has_password? | |
validates_with_method :proper_user_params? | |
def [](key) | |
self.send(key) | |
end | |
def sanitize! | |
valid? | |
self | |
end | |
private | |
def has_password? | |
set_default_password if self[:user][:password].blank? | |
end | |
def set_default_password | |
self[:user][:password] = self[:user][:password_confirmation] = Devise.friendly_token.first(6) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment