Sha256: e6a72dc1fb12bafb75907cc7382879a88b86675733e02294184fb8c377371359
Contents?: true
Size: 1.4 KB
Versions: 27
Compression:
Stored size: 1.4 KB
Contents
# frozen_string_literal: true # encoding: utf-8 module Mongoid module Persistable # Defines behavior for persistence operations that save documents. # # @since 4.0.0 module Savable # Save the document - will perform an insert if the document is new, and # update if not. # # @example Save the document. # document.save # # @param [ Hash ] options Options to pass to the save. # # @return [ true, false ] True is success, false if not. # # @since 1.0.0 def save(options = {}) if new_record? !insert(options).new_record? else update_document(options) end end # Save the document - will perform an insert if the document is new, and # update if not. If a validation error occurs an error will get raised. # # @example Save the document. # document.save! # # @param [ Hash ] options Options to pass to the save. # # @raise [ Errors::Validations ] If validation failed. # @raise [ Errors::Callback ] If a callback returns false. # # @return [ true, false ] True if validation passed. # # @since 1.0.0 def save!(options = {}) unless save(options) fail_due_to_validation! unless errors.empty? fail_due_to_callback!(:save!) end true end end end end
Version data entries
27 entries across 27 versions & 2 rubygems