module DataMapper::Validations
Constants
- VERSION
Public Class Methods
included(model)
click to toggle source
# File lib/dm-validations.rb, line 30 def self.included(model) model.extend ClassMethods end
Public Instance Methods
errors()
click to toggle source
Return the ValidationErrors
@api public
# File lib/dm-validations.rb, line 61 def errors @errors ||= ValidationErrors.new(self) end
save(context = default_validation_context)
click to toggle source
Ensures the object is valid for the context provided, and otherwise throws :halt and returns false.
@api public
Calls superclass method
# File lib/dm-validations.rb, line 38 def save(context = default_validation_context) model.validators.assert_valid(context) Validations::Context.in_context(context) { super() } end
save_self(*)
click to toggle source
@api private
Calls superclass method
# File lib/dm-validations.rb, line 50 def save_self(*) if Validations::Context.any? && !valid?(model.validators.current_context) false else super end end
update(attributes = {}, context = default_validation_context)
click to toggle source
@api public
Calls superclass method
# File lib/dm-validations.rb, line 44 def update(attributes = {}, context = default_validation_context) model.validators.assert_valid(context) Validations::Context.in_context(context) { super(attributes) } end
valid?(context = :default)
click to toggle source
Check if a resource is valid in a given context
@api public
# File lib/dm-validations.rb, line 84 def valid?(context = :default) model = respond_to?(:model) ? self.model : self.class model.validators.execute(context, self) end
valid_for_default?()
click to toggle source
Alias for valid?(:default)
TODO: deprecate
# File lib/dm-validations.rb, line 77 def valid_for_default? valid?(:default) end
validatable?()
click to toggle source
Mark this resource as validatable. When we validate associations of a resource we can check if they respond to validatable? before trying to recursively validate them
@api semipublic
# File lib/dm-validations.rb, line 70 def validatable? true end
validation_property_value(name)
click to toggle source
@api semipublic
# File lib/dm-validations.rb, line 90 def validation_property_value(name) __send__(name) if respond_to?(name, true) end