Renamed new_document? and new_model? to simply new?

This commit is contained in:
Peter Gumeson 2009-06-04 20:44:44 -07:00
parent b4e2250668
commit 76b1563539
8 changed files with 26 additions and 26 deletions

View file

@ -27,7 +27,7 @@ module CouchRest
end
# returns true if the document has never been saved
def new_document?
def new?
!rev
end
@ -67,7 +67,7 @@ module CouchRest
# Returns the CouchDB uri for the document
def uri(append_rev = false)
return nil if new_document?
return nil if new?
couch_uri = "http://#{database.uri}/#{CGI.escape(id)}"
if append_rev == true
couch_uri << "?rev=#{rev}"

View file

@ -17,7 +17,7 @@ module CouchRest
end
def apply_defaults
return if self.respond_to?(:new_document?) && (new_document? == false)
return if self.respond_to?(:new?) && (new? == false)
return unless self.class.respond_to?(:properties)
return if self.class.properties.empty?
# TODO: cache the default object

View file

@ -37,10 +37,10 @@ module CouchRest
# False if the casted model has already
# been saved in the containing document
def new_model?
def new?
!@document_saved
end
alias :new_record? :new_model?
alias :new_record? :new?
# Sets the attributes from a hash
def update_attributes_without_saving(hash)

View file

@ -64,7 +64,7 @@ module CouchRest
save_callback :before do |object|
object['updated_at'] = Time.now
object['created_at'] = object['updated_at'] if object.new_document?
object['created_at'] = object['updated_at'] if object.new?
end
EOS
end
@ -145,7 +145,7 @@ module CouchRest
end
# for compatibility with old-school frameworks
alias :new_record? :new_document?
alias :new_record? :new?
# Trigger the callbacks (before, after, around)
# and create the document
@ -166,7 +166,7 @@ module CouchRest
# unlike save, create returns the newly created document
def create_without_callbacks(bulk =false)
raise ArgumentError, "a document requires a database to be created to (The document or the #{self.class} default database were not set)" unless database
set_unique_id if new_document? && self.respond_to?(:set_unique_id)
set_unique_id if new? && self.respond_to?(:set_unique_id)
result = database.save_doc(self, bulk)
(result["ok"] == true) ? self : false
end
@ -181,7 +181,7 @@ module CouchRest
# only if the document isn't new
def update(bulk = false)
caught = catch(:halt) do
if self.new_document?
if self.new?
save(bulk)
else
_run_update_callbacks do
@ -197,7 +197,7 @@ module CouchRest
# and save the document
def save(bulk = false)
caught = catch(:halt) do
if self.new_document?
if self.new?
_run_save_callbacks do
save_without_callbacks(bulk)
end
@ -211,7 +211,7 @@ module CouchRest
# Returns a boolean value
def save_without_callbacks(bulk = false)
raise ArgumentError, "a document requires a database to be saved to (The document or the #{self.class} default database were not set)" unless database
set_unique_id if new_document? && self.respond_to?(:set_unique_id)
set_unique_id if new? && self.respond_to?(:set_unique_id)
result = database.save_doc(self, bulk)
mark_as_saved if result["ok"] == true
result["ok"] == true