Class: Humanoid::Commands::Save

Inherits:
Object
  • Object
show all
Defined in:
lib/humanoid/commands/save.rb

Class Method Summary collapse

Class Method Details

.execute(doc, validate = true) ⇒ Object

Performs a save of the supplied Document, handling all associated callbacks and validation.

Options:

doc: A Document that is going to be persisted.

Returns: true if validation passes, false if not.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/humanoid/commands/save.rb', line 13

def self.execute(doc, validate = true)
  return false if validate && !doc.valid?
  doc.run_callbacks :before_save
  parent = doc._parent
  if parent ? Save.execute(parent, validate) : doc.collection.save(doc.raw_attributes, :safe => Humanoid.persist_in_safe_mode)
    doc.new_record = false
    doc.run_callbacks :after_save
    return true
  else
    return false
  end
end