module ActiveFedora::Validations

def perform_validations(options={})

def perform_validations(options={})
  perform_validation = options[:validate] != false
  perform_validation ? valid?(options[:context]) : true
end

def required?(key)

Returns:
  • (Boolean) - is it required or not

Parameters:
  • key (Symbol) -- a field
def required?(key)
  self.class.validators_on(key).any?{|v| v.kind_of? ActiveModel::Validations::PresenceValidator}
end

def save(options={})

replaced with this when the validations module is mixed in, which it is by default.
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={})

if the record is not valid.
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(RecordInvalid.new(self))
end

def valid?(context = nil)

some :on option will only run in the specified context.
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 ||= (new_record? ? :create : :update)
  output = super(context)
  errors.empty? && output
end