Thread Safe Current Class Instance
Implementation
Include the gem:
gem 'current_instance'
Use Like So:
class User < ActiveRecord::Base
include CurrentInstance
end
Function
Set User.current by assigning an object
User.current = User.first
User.current #=> <User id: 1, name: "Flinn"...>
User.current = nil
User.current #=> nil
Set Food.current by id
Food.current_id #=> nil
Food.current_id = 1
Food.current #=> <Food id: 1, name: "Fondue"...>
Food.current_id = nil
Food.current #=> nil
TODO
- Tests
- Caching