lib/couchrest/model/validations.rb in couchrest_model-1.1.0.rc1 vs lib/couchrest/model/validations.rb in couchrest_model-1.1.0

- old
+ new

@@ -11,25 +11,36 @@ module Model # Validations may be applied to both Model::Base and Model::CastedModel module Validations extend ActiveSupport::Concern - included do - include ActiveModel::Validations - include ActiveModel::Validations::Callbacks + include ActiveModel::Validations + + # Determine if the document is valid. + # + # @example Is the document valid? + # person.valid? + # + # @example Is the document valid in a context? + # person.valid?(:create) + # + # @param [ Symbol ] context The optional validation context. + # + # @return [ true, false ] True if valid, false if not. + # + def valid?(context = nil) + super context ? context : (new? ? :create : :update) end - module ClassMethods - - # Validates the associated casted model. This method should not be + + # Validates the associated casted model. This method should not be # used within your code as it is automatically included when a CastedModel # is used inside the model. - # def validates_casted_model(*args) validates_with(CastedModelValidator, _merge_attributes(args)) end - + # Validates if the field is unique for this type of document. Automatically creates # a view if one does not already exist and performs a search for all matching # documents. # # Example: