current_object

Do you need to keep track of a current user, account, page, etc? The current_object gem does just that.

current_object takes the same approach to keeping track of a user as SentientUser by David Bock, but goes completely class agnostic. You can even keep track of multiple “current” objects at once.

Usage

Just require the current_object gem into your project and include CurrentObject.


# foo.rb
require 'current_object'

class Foo
  include CurrentObject
end

# using my foo class

@foo = Foo.new

# time to make this my current foo instance
@foo.current!

# what is my current foo instance?
Foo.current