tbpro/mongoid_userstamp — pull request #18 by johnnyshields (2014-08-01 09:16:22+00:00)
Title: User Relation + Multi-User + Thread Safety

This commit adds the following features. It is a breaking change from the previous version, and may require user to run migrations on their existing data (should be self-explanatory)

Apologies for putting 3 features in one commit, this is basically a refactor of the gem. I have used this in production for nearly 6 months and confirmed it is stable.

#### Created/Updated By fields are now Mongoid `belongs_to` Relations

```ruby
# Creator instance | Updater instance
p.created_by | p.updated_by
# =>

# Creator ObjectID | Updater ObjectID
p.created_by_id | p.updated_by_id
# => BSON::ObjectId('4f7c719f476da850ba000039')
```

#### Multiple User Model Classes

```ruby
class Product
include Mongoid::Document
include Mongoid::Userstamp

# optional class-level config override
mongoid_userstamp user_model: 'MyUser',
created_name: :creator,
updated_name: :updater,
end

class MyUser
include Mongoid::Document
include Mongoid::Userstamp::User

# optional class-level config override
mongoid_userstamp_user reader: :current_my_user
end
```

#### Thread Safety

Mongoid::Userstamp stores all-related user variables in `Thread.current`. If the [RequestStore](https://github.com/steveklabnik/request_store) gem is installed, Mongoid::Userstamp will automatically store variables in the `RequestStore.store` instead. RequestStore is recommended for threaded web servers like Thin or Puma.