Added validation callbacks to extended documents and casted models
This commit is contained in:
parent
91cd1d9c7b
commit
b4e2250668
5 changed files with 77 additions and 4 deletions
|
@ -51,6 +51,9 @@ module CouchRest
|
|||
def self.included(base)
|
||||
base.extlib_inheritable_accessor(:auto_validation)
|
||||
base.class_eval <<-EOS, __FILE__, __LINE__
|
||||
# Callbacks
|
||||
define_callbacks :validate
|
||||
|
||||
# Turn off auto validation by default
|
||||
self.auto_validation ||= false
|
||||
|
||||
|
@ -72,6 +75,7 @@ module CouchRest
|
|||
|
||||
base.extend(ClassMethods)
|
||||
base.class_eval <<-EOS, __FILE__, __LINE__
|
||||
define_callbacks :validate
|
||||
if method_defined?(:_run_save_callbacks)
|
||||
save_callback :before, :check_validations
|
||||
end
|
||||
|
@ -147,7 +151,9 @@ module CouchRest
|
|||
valid = recursive_valid?(prop, context, valid) && valid
|
||||
end
|
||||
end
|
||||
target.class.validators.execute(context, target) && valid
|
||||
target._run_validate_callbacks do
|
||||
target.class.validators.execute(context, target) && valid
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ module CouchRest
|
|||
module CastedModel
|
||||
|
||||
def self.included(base)
|
||||
base.send(:include, CouchRest::Callbacks)
|
||||
base.send(:include, CouchRest::Mixins::Properties)
|
||||
base.send(:attr_accessor, :casted_by)
|
||||
base.send(:attr_accessor, :document_saved)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue