BsonObjectIdValidations
Provides an ActiveModel validation that checks if an attribute represents a legal BSON::ObjectId .
Installation
Add this line to your application's Gemfile:
gem 'bson_object_id_validations'
And then execute:
$ bundle
Or install it yourself as:
$ gem install bson_object_id_validations
Usage
Validate that the specified attribute's value is a legal BSON::ObjectId .
class User
include ActiveModel::Validations
include BsonObjectIdValidations
attr_accessor :mongo_id
validates :mongo_id, :legal_bson_object_id => true
end
user = User.new :mongo_id => "invalid"
user.valid?
=> false
user.errors
=> {:mongo_id=>["is an invalid BSON::ObjectId"]}
user.mongo_id = BSON::ObjectId.new.to_s
user.valid?
=> true
Contributing
- Fork it.
- Create your feature branch (
git checkout -b my-new-feature
). - Commit your changes (
git commit -am 'Added some feature'
). - Push to your branch (
git push origin my-new-feature
). - Send a pull request.