Module: Zdi::DocumentHelpers

Included in:
DocumentWrapper
Defined in:
lib/zentradi/document_helpers.rb

Instance Method Summary collapse

Instance Method Details

#destroyObject



22
23
24
# File 'lib/zentradi/document_helpers.rb', line 22

def destroy
  @collection.remove("_id" => id)
end

#idObject



4
5
6
# File 'lib/zentradi/document_helpers.rb', line 4

def id
  super || _id
end

#new?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/zentradi/document_helpers.rb', line 8

def new?
  id.nil? || @collection.find("_id" => id).count == 0
end

#saveObject

Raises:

  • (RuntimeError)


12
13
14
15
16
17
18
19
20
# File 'lib/zentradi/document_helpers.rb', line 12

def save
  if id.nil?
    self.id = @collection.save(self)
  else
    @collection.update({"_id" => id}, self)
  end
  raise RuntimeError, "document lacks an id after save!" if id.nil?
  self
end