Skip to content

Generate unique token in a Mongoid field. Mongoid version of Ryan Bates uniquify gem.

License

Notifications You must be signed in to change notification settings

sagarkt/mongoid_uniquify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mongoid_uniquify

Generate unique token in a Mongoid field. Mongoid version of Ryan Bates uniquify gem.

Installation

gem install mongoid_uniquify

In your Gemfile

gem "mongoid_uniquify"

REQUIREMENTS:

  • mongoid 2.0.0 or later

USAGE:

class Project
  include Mongoid::Document
  include Mongoid::Uniquify

  uniquify :token, :length => 7, :chars => ('a'..'z').to_a + ('0'..'9').to_a

  field :token, :type => String

  # ...
end

If you want to use generated token as key and add unique index, do something like below.

class Project
  include Mongoid::Document
  include Mongoid::Uniquify

  uniquify :token, :length => 7, :chars => ('a'..'z').to_a + ('0'..'9').to_a

  field :token, :type => String
  key :token

  index :token, :unique => true

  # ...
end

Copyright © 2011 Kichiro IKEMOTO. See LICENSE.txt for further details.

About

Generate unique token in a Mongoid field. Mongoid version of Ryan Bates uniquify gem.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages