Repository is archived
No commit activity in last 3 years
No release in over 3 years
adds uniquness validation by using a design doc view
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.2.9

Runtime

>= 0.34
 Project Readme

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