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

Version Path
mongoid-7.3.5 lib/mongoid/persistable/savable.rb
mongoid-7.3.4 lib/mongoid/persistable/savable.rb
mongoid-7.1.11 lib/mongoid/persistable/savable.rb
mongoid-7.2.6 lib/mongoid/persistable/savable.rb
mongoid-7.3.3 lib/mongoid/persistable/savable.rb
mongoid-7.3.2 lib/mongoid/persistable/savable.rb
mongoid-7.2.5 lib/mongoid/persistable/savable.rb
mongoid-7.1.10 lib/mongoid/persistable/savable.rb
mongoid-7.1.9 lib/mongoid/persistable/savable.rb
mongoid-7.2.4 lib/mongoid/persistable/savable.rb
mongoid-7.3.1 lib/mongoid/persistable/savable.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mongoid-7.1.7/lib/mongoid/persistable/savable.rb
mongoid-7.3.0 lib/mongoid/persistable/savable.rb
mongoid-7.2.3 lib/mongoid/persistable/savable.rb
mongoid-7.1.8 lib/mongoid/persistable/savable.rb
mongoid-7.2.2 lib/mongoid/persistable/savable.rb
mongoid-7.2.1 lib/mongoid/persistable/savable.rb
mongoid-7.1.7 lib/mongoid/persistable/savable.rb
mongoid-7.2.0 lib/mongoid/persistable/savable.rb
mongoid-7.1.6 lib/mongoid/persistable/savable.rb