module Dinamo::Model::Validation
Public Instance Methods
errors()
click to toggle source
# File lib/dinamo/model/validation.rb, line 13 def errors @errors ||= Dinamo::Model::Errors.new end
valid?()
click to toggle source
# File lib/dinamo/model/validation.rb, line 9 def valid? validate end
validate()
click to toggle source
# File lib/dinamo/model/validation.rb, line 17 def validate errors.clear validate_unsupported_fields validate_required_attributes validate_by_using_validators errors.empty? end
Private Instance Methods
validate_by_using_validators()
click to toggle source
# File lib/dinamo/model/validation.rb, line 27 def validate_by_using_validators self.class.validators.each do |validator| validator.validate(self) end end
validate_required_attributes()
click to toggle source
# File lib/dinamo/model/validation.rb, line 43 def validate_required_attributes self.class.required_fields.map(&:name).each do |attr| message = "%p attribute is required" % attr errors.add(attr, message) unless attributes.has_key?(attr) end end
validate_unsupported_fields()
click to toggle source
# File lib/dinamo/model/validation.rb, line 33 def validate_unsupported_fields supported_fields = self.class.supported_fields.map(&:name) attributes.each do |(attr, _)| unless supported_fields.include?(attr.to_s) message = "%p attribute is not supported" % [attr, self.class] errors.add(attr, message) end end end