module ActiveFedora::Validations
def default_validation_context
def default_validation_context new_record? ? :create : :update end
def perform_validations(options = {}) # :nodoc:
def perform_validations(options = {}) # :nodoc: options[:validate] == false || valid?(options[:context]) end
def raise_validation_error
def raise_validation_error raise RecordInvalid, self end
def required?(key)
-
(Boolean)
- is it required or not
Parameters:
-
key
(Symbol
) -- a field
def required?(key) self.class.validators_on(key).any? { |v| v.is_a? ActiveModel::Validations::PresenceValidator } end
def save(options = {})
The validation process on save can be skipped by passing :validate => false. The regular Base#save method is
def save(options = {}) perform_validations(options) ? super : false end
def save!(options = {})
Attempts to save the record just like Base#save but will raise a +RecordInvalid+ exception instead of returning false
def save!(options = {}) perform_validations(options) ? super : raise_validation_error end
def valid?(context = nil)
Validations with no :on option will run no matter the context. Validations with
new_record? is true, and to :update if it is not.
If the argument is false (default is +nil+), the context is set to :create if
false otherwise.
Runs all the validations within the specified context. Returns true if no errors are found,
def valid?(context = nil) context ||= default_validation_context output = super(context) errors.empty? && output end