What is analog in datamapper for .present? method?
I have code from rails app an d wan t to reuse it is Sinatra
ex:
def encrypt_password
if password.present?
self.password_salt = BCrypt::Engine.generate_salt
self.password_hash = BCrypt::Engine.hash_secret(password, password_salt)
end
end
in model I ave before save callback
before :save, :encrypt_password
The
present?Method in ActiveSupport is defined as follows:(Source: http://api.rubyonrails.org/classes/Object.html#method-i-present-3F)
You could extend
Objectlike that, too. It checks whether the Object is not blank. The methodblank?itself checks whether the Object responds toempty?. This is mostly for strings. If the Object does not respond toempty?, the method simply returns!self. Sopresent?would simply returnself. Therefore you could also write your code asThe only advantage of the
present?method is, that it does not treat an empty string as present, whereas the second method does.