https://github.com/ioquatix/activerecord-rack
https://github.com/ioquatix/activerecord-rack
activerecord database middleware rack
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/ioquatix/activerecord-rack
- Owner: ioquatix
- Created: 2016-12-08T23:22:00.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-14T13:31:17.000Z (over 8 years ago)
- Last Synced: 2025-05-06T22:12:44.675Z (5 months ago)
- Topics: activerecord, database, middleware, rack
- Language: Ruby
- Size: 6.84 KB
- Stars: 13
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ActiveRecord::Rack
Provides database connection management for standalone ActiveRecord apps built on top of Rack.
[](http://travis-ci.org/ioquatix/activerecord-rack)
[](https://codeclimate.com/github/ioquatix/activerecord-rack)
[](https://coveralls.io/r/ioquatix/activerecord-rack)## Motivation
Unfortunately, in ActiveRecord 5.0, the `class ConnectionManagement` [was removed](https://github.com/rails/rails/issues/26947). So, I've copied it from 4.2 and released it here with minor improvements.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'activerecord-rack'
```## Usage
In your `config.ru`, before any middleware that would use the database, insert:
```ruby
require 'active_record/rack'# Middleware below this point may require database access:
use ActiveRecord::Rack::ConnectionManagement
```### Testing
I removed the auto-detection of a test environment from the original middleware. I did this because I like predictable and simple logic. If you want to restore this behaviour, I suggest you write
```ruby
unless RACK_ENV == :test
use ActiveRecord::Rack::ConnectionManagement
end
```## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request## See Also
- [ActiveRecord::Migrations](https://github.com/ioquatix/activerecord-migrations)
## License
Released under the MIT license.
Copyright, 2016, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.