Sha256: 04cb29343aef5d9a37768f9f40eb64cdfe11d3c4c208e48a001285f1b3fbf72b

Contents?: true

Size: 676 Bytes

Versions: 7

Compression:

Stored size: 676 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 doc.valid?
        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

7 entries across 7 versions & 1 rubygems

Version Path
mongoid-0.10.4 lib/mongoid/commands/save.rb
mongoid-0.10.3 lib/mongoid/commands/save.rb
mongoid-0.10.2 lib/mongoid/commands/save.rb
mongoid-0.10.1 lib/mongoid/commands/save.rb
mongoid-0.10.0 lib/mongoid/commands/save.rb
mongoid-0.9.12 lib/mongoid/commands/save.rb
mongoid-0.9.11 lib/mongoid/commands/save.rb