DataMapper:Validations
DataMapper::Validations
25 module DataMapper
26 module Validations
27
28 Model.append_inclusions self
29
30 def self.included(model)
31 model.extend ClassMethods
32 end
33
34 # Ensures the object is valid for the context provided, and otherwise
35 # throws :halt and returns false.
36 #
37 # @api public
38 def save(context = default_validation_context)
39 model.validators.assert_valid(context)
40 debugger
41 Validations::Context.in_context(context) { super() }
42 end
43
44 # @api public
45 def update(attributes = {}, context = default_validation_context)
46 model.validators.assert_valid(context)
47 Validations::Context.in_context(context) { super(attributes) }
48 end
49
50 # @api private
51 def save_self(*)
52 if Validations::Context.any? && !valid?(model.validators.current_context)
53 false
54 else
55 super
56 end
57 end
58
59 # Return the ValidationErrors
60 #
61 # @api public
62 def errors
63 @errors ||= ValidationErrors.new(self)
55,7 17%
25 module DataMapper
26 module Validations
27
28 Model.append_inclusions self
29
30 def self.included(model)
31 model.extend ClassMethods
32 end
33
34 # Ensures the object is valid for the context provided, and otherwise
35 # throws :halt and returns false.
36 #
37 # @api public
38 def save(context = default_validation_context)
39 model.validators.assert_valid(context)
40 debugger
41 Validations::Context.in_context(context) { super() }
42 end
43
44 # @api public
45 def update(attributes = {}, context = default_validation_context)
46 model.validators.assert_valid(context)
47 Validations::Context.in_context(context) { super(attributes) }
48 end
49
50 # @api private
51 def save_self(*)
52 if Validations::Context.any? && !valid?(model.validators.current_context)
53 false
54 else
55 super
56 end
57 end
58
59 # Return the ValidationErrors
60 #
61 # @api public
62 def errors
63 @errors ||= ValidationErrors.new(self)
55,7 17%