May 26, 2014
Previously I mentioned how to achieve Uniqueness Validation With Ripple.
Similarly, Ripple doesn’t provide direct method for adding validation only on create while trying to implement Riak On Rails using Ripple as modeling layer. This is very much necessary for the validation of properties such as password which are to be checked only while being created. Below is the code sample I developed for validation on create manually.
class User
include Ripple::Document
attr_accessor :password
validates :password, :presence => true, :length => :in => 8..20 , :if => :not_created?
private
def not_created?
!self.key.present?
end
After searching for a while and trying to think of a way, I realized that the key for the object is only determined after it is saved or created. Also
Continue reading →
May 25, 2014
I’m a riak newbie who is trying to implement Riak On Rails using Ripple as modeling layer. But while creating User model, I wanted validation for uniqueness of user. Validation such as presence is available with Ripple but I couldn’t find proper validation method directly provided for the uniqueness. So, below is the sample code of User model I developed for validation.
class User
include Ripple::Document
VALID_EMAIL_REGEX = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]2,)\z/i
property :email, String, :presence => true, format: with: VALID_EMAIL_REGEX , :index => true
validate :unique_email_address?
private
def unique_email_address?
errors.add(:email, 'The email is already taken.') if User.find_by_index('email', "#self.email").any?
end
end
This is simple but it was actually difficult to find the available methods in Ripple. In the code above “index: true” enables the property to be indexed automaticall
Continue reading →