lib/versioned.rb in versioned-0.2.0 vs lib/versioned.rb in versioned-0.2.1

- old
+ new

@@ -10,27 +10,25 @@ end module LockingInstanceMethods private #new? isn't working - def is_new_document? - (read_attribute(self.version_lock_key).blank? && changes[self.version_lock_key.to_s].blank?) || - (changes[self.version_lock_key.to_s] && changes[self.version_lock_key.to_s].first.blank?) - end def prep_lock_version old = read_attribute(self.version_lock_key) - if !is_new_document? || old.blank? + if !new? || old.blank? v = (Time.now.to_f * 1000).ceil.to_s write_attribute self.version_lock_key, v end old end def save_to_collection(options = {}) current_version = prep_lock_version - if is_new_document? + old_new = new? + @new = false + if old_new collection.insert(to_mongo, :safe => true) else selector = { :_id => read_attribute(:_id), self.version_lock_key => current_version } #can't upsert, safe must be true for this to work result = collection.update(selector, to_mongo, :upsert => false, :safe => true) @@ -78,10 +76,10 @@ if condition.is_a?(Range) conditions = {'$gte' => condition.first, '$lte' => condition.last} else conditions = condition end - find(:all, + all( :number => conditions, :order => "number #{(from_number > to_number) ? 'DESC' : 'ASC'}" ) end