lib/couchrest/model/persistence.rb
def unique_id(method = nil, &block)
          if method
            define_method :set_unique_id do
              self['_id'] ||= self.send(method)
            end
          elsif block
            define_method :set_unique_id do
              uniqid = block.call(self)
              raise ArgumentError, "unique_id block must not return nil" if uniqid.nil?
              self['_id'] ||= uniqid
            end
          end
        end
# Name a method that will be called before the document is first saved,
# which returns a string to be used for the document's <tt>_id</tt>.
#
# Because CouchDB enforces a constraint that each id must be unique,
# this can be used to enforce eg: uniq usernames. Note that this id
# must be globally unique across all document types which share a
# database, so if you'd like to scope uniqueness to this class, you
# should use the class name as part of the unique id.
Name a method that will be called before the document is first saved,
which returns a string to be used for the document's _id.

Because CouchDB enforces a constraint that each id must be unique,
this can be used to enforce eg: uniq usernames. Note that this id
must be globally unique across all document types which share a
database, so if you'd like to scope uniqueness to this class, you
should use the class name as part of the unique id.
Name a method that will be called before the document is first saved which returns a string to be used for the document ' s _id . Because CouchDB enforces a constraint that each id must be unique this can be used to enforce eg : uniq usernames . Note that this id must be globally unique across all document types which share a database so if you ' d like to scope uniqueness to this class you should use the class name as part of the unique id .
def unique_id(method = nil, &block)
          if method
            define_method :set_unique_id do
              self['_id'] ||= self.send(method)
            end
          elsif block
            define_method :set_unique_id do
              uniqid = block.call(self)
              raise ArgumentError, "unique_id block must not return nil" if uniqid.nil?
              self['_id'] ||= uniqid
            end
          end
        end
def unique_id ( method = nil , & block ) if method define_method :set_unique_id do self [ '_id' ] ||= self . send ( method ) end elsif block define_method :set_unique_id do uniqid = block . call ( self ) raise ArgumentError , "unique_id block must not return nil" if uniqid . nil? self [ '_id' ] ||= uniqid end end end
Name a method that will be called before the document is first saved,
which returns a string to be used for the document's <tt>_id</tt>.
Name a method that will be called before the document is first saved which returns a string to be used for the document ' s <tt > _id< / tt > .
method
block