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

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) _parent_document

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



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

def _parent_document
  @_parent_document
end

Instance Method Details

- (Object) _root_document

The root Document to which this embedded document belongs.



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

def _root_document
  @_parent_document.try(:_root_document)
end

- (Boolean) new?

Whether the root document is unsaved.

Returns:



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

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

- (Object) save(*args)

Saves this embedded document by delegating to the root document.



69
70
71
72
73
74
75
# File 'ripple/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

- (Object) update_attribute(attribute, value)

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



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

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

- (Object) update_attributes(attrs)

Sets this embedded documents attributes and saves the root document.



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

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