Sha256: de1662fabc1f7008b2277eb24b47960dfe82946cf6ed831240291dbd05b8953a

Contents?: true

Size: 687 Bytes

Versions: 2

Compression:

Stored size: 687 Bytes

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Commands
    class Save
      # Performs a save of the supplied +Document+, handling all associated
      # callbacks and validation.
      #
      # Options:
      #
      # doc: A +Document+ that is going to be persisted.
      #
      # Returns: +Document+ if validation passes, +false+ if not.
      def self.execute(doc)
        return false unless Validate.execute(doc)
        doc.run_callbacks :before_save
        parent = doc.parent
        doc.new_record = false
        parent ? Save.execute(parent) : doc.collection.save(doc.attributes)
        doc.run_callbacks :after_save
        return true
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mongoid-0.9.10 lib/mongoid/commands/save.rb
mongoid-0.9.9 lib/mongoid/commands/save.rb