DataMapper-style persistence layer over Mongoid.
gem "mongoid_mapper", github: "wenoa/mongoid-mapper"When the gem is required, Mongoid::Document is reopened to inject extra capabilities into any class
that includes it:
fieldremoves the previously defined methods before redefining a field.persisted_methodpersists a method's result into a field viabefore_save.autosave_onsaves the document after invoking a method.- Forces Mongoid's
initialize, for domain models with their own constructors.
In addition, TransactionAwareCollection makes MongoDB driver aggregations participate in the active
transaction, so they see the changes pending commit.
A unique index violation (error code 11000) raises Mongo::Error::DuplicateKey instead of a generic
Mongo::Error::OperationFailure, so callers can rescue a duplicate directly:
begin
inventariable.save!
rescue Mongo::Error::DuplicateKey
# ...
endThe suite expects a MongoDB replica set running on the default port:
docker run --rm -p 27017:27017 --hostname localhost mongodb/mongodb-atlas-local:8.0.4