0
@@ -107,35 +107,32 @@ module ActiveCouch
0
- # Deletes a document from a CouchDB database.
0
+ # Deletes a document from a CouchDB database. This is an instance-level delete method.
0
+ # class Person < ActiveCouch::Base
0
+ # person = Person.create(:name => 'McLovin')
0
+ # person.delete # true
0
- raise A
ctiveCouchError, "You must specify a revision for the document to be deleted"
0
+ raise A
rgumentError, "You must specify a revision for the document to be deleted"
0
- raise ActiveCouchError, "You must specify an ID for the document to be deleted"
0
+ raise ArgumentError, "You must specify an ID for the document to be deleted"
0
+ response = connection.delete("/#{self.class.database_name}/#{id}?rev=#{rev}")
0
+ # Set the id and rev to nil, since the object has been successfully deleted from CouchDB
0
+ if response.code == '202'
0
+ self.id = nil; self.rev = nil
0
-
connection.delete("/#{self.class.database_name}/#{id}?rev=#{rev}")0
class << self # Class methods
0
- def inherited(subklass)
0
- # TODO: Need a cleaner way to do this
0
- subklass.instance_variable_set "@attributes", { :_id => Attribute.new(:_id, :with_default_value => nil),
0
- :_rev => Attribute.new(:_rev, :with_default_value => nil) }
0
- subklass.instance_variable_set "@associations", {}
0
- subklass.instance_variable_set "@connections", nil
0
- SPECIAL_MEMBERS.each do |k|
0
- subklass.instance_eval "def #{k}; @#{k}; end"
0
- class_of_active_couch_descendant(self)
0
# Returns the CouchDB database name that's backing this model. The database name is guessed from the name of the
0
# class somewhat similar to ActiveRecord conventions.
0
@@ -273,8 +270,11 @@ module ActiveCouch
0
# class Person < ActiveCouch::Base
0
+ # # This returns a single instance of an ActiveCouch::Base subclass
0
# people = Person.find(:first, :params => {:name => "McLovin"})
0
+ # # This returns an array of ActiveCouch::Base subclass instances
0
# person = Person.find(:all, :params => {:name => "McLovin"})
0
scope = arguments.slice!(0)
0
@@ -308,6 +308,24 @@ module ActiveCouch
0
+ # Deletes a document from the CouchDB database, based on the id and rev parameters passed to it.
0
+ # Returns true if the document has been deleted
0
+ # class Person < ActiveCouch::Base
0
+ # Person.delete(:id => 'abc-def', :rev => '1235')
0
+ def delete(options = {})
0
+ if options.nil? || !options.has_key?(:id) || !options.has_key?(:rev)
0
+ raise ArgumentError, "You must specify both an id and a rev for the document to be deleted"
0
+ response = connection.delete("/#{self.database_name}/#{options[:id]}?rev=#{options[:rev]}")
0
+ response.code == '202'
0
# Defines an "attribute" method. A new (class) method will be created with the
0
# given name. If a value is specified, the new method will
0
# return that value (as a string). Otherwise, the given block
0
@@ -338,6 +356,22 @@ module ActiveCouch
0
+ def inherited(subklass)
0
+ # TODO: Need a cleaner way to do this
0
+ subklass.instance_variable_set "@attributes", { :_id => Attribute.new(:_id, :with_default_value => nil),
0
+ :_rev => Attribute.new(:_rev, :with_default_value => nil) }
0
+ subklass.instance_variable_set "@associations", {}
0
+ subklass.instance_variable_set "@connections", nil
0
+ SPECIAL_MEMBERS.each do |k|
0
+ subklass.instance_eval "def #{k}; @#{k}; end"
0
+ class_of_active_couch_descendant(self)
0
# Returns the class descending directly from ActiveCouch in the inheritance hierarchy.
Comments
No one has commented yet.