Sha256: 4b294c455ea8fcdbfbd87edc35a1b58b9315ed8e2598e3b63ba3145314b9f6e8

Contents?: true

Size: 1.72 KB

Versions: 4

Compression:

Stored size: 1.72 KB

Contents

= Couchrest Uniqueness Validation

This is a simple add-on to {couchrest}[http://github.com/couchrest/couchrest] gem

Validates that the specified attribute is unique across documents with the same 
couchrest-type using a view.

== Install

  gem install couchrest-uniqueness-validation
  
== Usage

  require 'rubygems'
  require 'couchrest'
  require 'couchrest-uniqueness-validation'

  class User < CouchRest::ExtendedDocument
    include CouchRest::Validation
    
    property :nickname
    property :login

    view_by :nickname

    # assumes that a view :by_nickname is present
    validates_uniqueness_of :nickname

    # uses a different from default view 
    validates_uniqueness_of :login, :view => 'my_custom_view'

    # a call to valid? will return false unless no other document exists with
    # the same couchrest-type, nickname and login
  end

Note: at least two views should exist in the User design doc for this example to work - 
:by_nickname and :my_custom_view.

See {CouchRest Views docs}[http://rdoc.info/rdoc/couchrest/couchrest/blob/1b34fe4b60694683e98866a51c2109c1885f7e42/CouchRest/Mixins/Views/ClassMethods.html#view_by-instance_method] 
for more info on views.
  

== Note on Patches/Pull Requests
 
* Fork the {project}[http://github.com/crhym3/couchrest-uniqueness-validation].
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a
  future version unintentionally.
* Commit, do not mess with rakefile, version, or history.
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
* Send me a pull request. Bonus points for topic branches.

== Copyright

Copyright (c) 2010 alex@digns.com. See LICENSE for details.

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
couchrest-uniqueness-validation-0.2.1 README.rdoc
couchrest-uniqueness-validation-0.2.0 README.rdoc
couchrest-uniqueness-validation-0.1.1 README.rdoc
couchrest-uniqueness-validation-0.1.0 README.rdoc