Class: RailsAdmin::Adapters::Mongoid::Bson

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_admin/adapters/mongoid/bson.rb

Constant Summary collapse

OBJECT_ID =
if defined?(Moped::BSON)
  Moped::BSON::ObjectId
elsif defined?(BSON::ObjectId)
  BSON::ObjectId
end

Class Method Summary collapse

Class Method Details

.parse_object_id(value) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/rails_admin/adapters/mongoid/bson.rb', line 17

def parse_object_id(value)
  OBJECT_ID.from_string(value)
rescue StandardError => e
  raise e if %w[
    Moped::Errors::InvalidObjectId
    BSON::ObjectId::Invalid
    BSON::InvalidObjectId
    BSON::Error::InvalidObjectId
  ].exclude?(e.class.to_s)
end