RequestGlobal provides global storage per request for Rails. The core part of RequestGlobal is written in Ruby's C API.
Installation
Add this line to your Gemfile:
gem 'request_global'
And then execute:
$ bundle
Or install it yourself as:
$ gem install request_global
Usage
Each storage of request is a Hash.
# Setter methods
RequestGlobal.store(:foo, 1) #=> 1
RequestGlobal[:bar] = 2 #=> 2
# Getter methods
RequestGlobal.fetch(:bar) #=> 2
RequestGlobal[:foo] #=> 1
# Delete
RequestGlobal.delete(:bar)
# Clear storage of current request
RequestGlobal.clear!
No Rails?
RequestGlobal provides Railtie which configures Rack middleware. However, if you're not using Rails, use middleware yourself like following:
use RequestGlobal::Middleware
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/cryeo/request_global.
License
The gem is available as open source under the terms of the MIT License.