No commit activity in last 3 years
No release in over 3 years
Provides an ActiveModel validation that checks if an attribute represents a legal BSON::ObjectId .
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0.9.0
>= 2.8

Runtime

 Project Readme

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

  1. Fork it.
  2. Create your feature branch (git checkout -b my-new-feature).
  3. Commit your changes (git commit -am 'Added some feature').
  4. Push to your branch (git push origin my-new-feature).
  5. Send a pull request.