Module: Ripple::EmbeddedDocument::Persistence::InstanceMethods

Defined in:
lib/ripple/embedded_document/persistence.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_parent_documentObject

The parent document to this embedded document. This may be a Document or another Ripple::EmbeddedDocument.



44
45
46
# File 'lib/ripple/embedded_document/persistence.rb', line 44

def _parent_document
  @_parent_document
end

Instance Method Details

#_root_documentObject

The root Document to which this embedded document belongs.



83
84
85
# File 'lib/ripple/embedded_document/persistence.rb', line 83

def _root_document
  @_parent_document.try(:_root_document)
end

#attributes_for_persistenceObject



78
79
80
# File 'lib/ripple/embedded_document/persistence.rb', line 78

def attributes_for_persistence
  attributes.merge("_type" => self.class.name)
end

#new?Boolean

Whether the root document is unsaved.

Returns:



47
48
49
50
51
52
53
# File 'lib/ripple/embedded_document/persistence.rb', line 47

def new?
  if _root_document
    _root_document.new?
  else
    true
  end
end

#save(*args) ⇒ Object

Saves this embedded document by delegating to the root document.



69
70
71
72
73
74
75
# File 'lib/ripple/embedded_document/persistence.rb', line 69

def save(*args)
  if _root_document
    _root_document.save(*args)
  else
    raise NoRootDocument.new(self, :save)
  end
end

#update_attribute(attribute, value) ⇒ Object

Updates this embedded document’s attribute and saves the root document, skipping validations.



63
64
65
66
# File 'lib/ripple/embedded_document/persistence.rb', line 63

def update_attribute(attribute, value)
  send("#{attribute}=", value)
  save(:validate => false)
end

#update_attributes(attrs) ⇒ Object

Sets this embedded documents attributes and saves the root document.



56
57
58
59
# File 'lib/ripple/embedded_document/persistence.rb', line 56

def update_attributes(attrs)
  self.attributes = attrs
  save
end