Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
adds validates_uniqueness_of validator to CouchRest::Validation
Ruby
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.document
.gitignore
LICENSE
README.rdoc
Rakefile adding specs and a couple rake tasks; formatting readme.
VERSION

README.rdoc

Couchrest Uniqueness Validation

This is a simple add-on to 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 for more info on views.

Note on Patches/Pull Requests

  • Fork the project.

  • 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 © 2010 alex@digns.com. See LICENSE for details.

Something went wrong with that request. Please try again.