Sha256: 2933fe08c74a1ed0204261fff23aee9eafb232a63f53da35f7183573f9512048

Contents?: true

Size: 765 Bytes

Versions: 13

Compression:

Stored size: 765 Bytes

Contents

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
        if parent
          Save.execute(parent)
        else
          collection = doc.collection
          collection ? collection.save(doc.attributes) : raise(MissingParentError.new(doc))
        end
        doc.run_callbacks :after_save
        return doc
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
mongoid-0.9.4 lib/mongoid/commands/save.rb
mongoid-0.9.3 lib/mongoid/commands/save.rb
mongoid-0.9.2 lib/mongoid/commands/save.rb
mongoid-0.9.1 lib/mongoid/commands/save.rb
mongoid-0.9.0 lib/mongoid/commands/save.rb
mongoid-0.8.10 lib/mongoid/commands/save.rb
mongoid-0.8.9 lib/mongoid/commands/save.rb
mongoid-0.8.8 lib/mongoid/commands/save.rb
mongoid-0.8.7 lib/mongoid/commands/save.rb
mongoid-0.8.6 lib/mongoid/commands/save.rb
mongoid-0.8.5 lib/mongoid/commands/save.rb
mongoid-0.8.4 lib/mongoid/commands/save.rb
mongoid-0.8.3 lib/mongoid/commands/save.rb