Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/instructure/guardrail
ActiveRecord extension to allow multiple database environments (secondary, deploy) enabling least privilege when possible.
https://github.com/instructure/guardrail
Last synced: 7 days ago
JSON representation
ActiveRecord extension to allow multiple database environments (secondary, deploy) enabling least privilege when possible.
- Host: GitHub
- URL: https://github.com/instructure/guardrail
- Owner: instructure
- License: mit
- Created: 2013-03-29T19:29:24.000Z (over 11 years ago)
- Default Branch: main
- Last Pushed: 2024-01-25T19:01:44.000Z (10 months ago)
- Last Synced: 2024-10-29T23:19:22.437Z (15 days ago)
- Language: Ruby
- Homepage:
- Size: 64.5 KB
- Stars: 17
- Watchers: 12
- Forks: 14
- Open Issues: 4
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
GuardRail
==========## About
GuardRail is a thin wrapper around Rail 6.1's native role switching.
## Installation
Add `gem 'guardrail'` to your Gemfile.
## Usage
See https://guides.rubyonrails.org/active_record_multiple_databases.html. GuardRail simply adds
syntactic sugar to easily switch to different roles:```ruby
def some_method
GuardRails.activate(:secondary) do
MyModel.some_really_long_query
end
end
```Additionally you can include GuardRail::HelperMethods and use several helpers
to execute methods on specific environments:```ruby
class SomeModel
include GuardRail::HelperMethodsdef expensive_read_only
...
end
guard_rail_method :expensive_read_only, environment: :replicadef self.class_level_expensive_read_only
...
end
guard_rail_class_method :class_level_expensive_read_only, environment: :replica# helpers for multiple methods are also available
guard_rail_methods :instance_method_foo, :instance_method_bar, environment: :replica
guard_rail_class_methods :class_method_foo, :class_method_bar, environment: :replica
end
```