https://github.com/ankane/ownership
Code ownership for Rails
https://github.com/ankane/ownership
Last synced: 7 months ago
JSON representation
Code ownership for Rails
- Host: GitHub
- URL: https://github.com/ankane/ownership
- Owner: ankane
- License: mit
- Created: 2017-11-06T01:56:53.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2025-10-26T23:20:25.000Z (8 months ago)
- Last Synced: 2025-11-12T16:10:20.719Z (7 months ago)
- Language: Ruby
- Homepage:
- Size: 62.5 KB
- Stars: 129
- Watchers: 2
- Forks: 12
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Ownership
Code ownership for Rails
Check out [Scaling the Monolith](https://ankane.org/scaling-the-monolith) for other tips
:tangerine: Battle-tested at [Instacart](https://www.instacart.com/opensource)
[](https://github.com/ankane/ownership/actions)
## Installation
Add this line to your application’s Gemfile:
```ruby
gem "ownership"
```
## Getting Started
Ownership provides the ability to specify owners for different parts of the codebase. **We highly recommend owners are teams rather than individuals.** You can then use this information however you’d like, like routing errors to the correct team.
## Specifying Ownership
### Controllers
```ruby
class OrdersController < ApplicationController
owner :logistics
end
```
You can use any options that `before_action` supports.
```ruby
class OrdersController < ApplicationController
owner :logistics, only: [:index]
owner :customers, except: [:index]
end
```
### Jobs
```ruby
class SomeJob < ApplicationJob
owner :logistics
end
```
### Anywhere
```ruby
owner :logistics do
# code
end
```
### Default
You can set a default owner with:
```ruby
Ownership.default_owner = :logistics
```
## Integrations
There are a few built-in integrations with other gems.
- [Active Record](#active-record)
- [AppSignal](#appsignal)
- [Honeybadger](#honeybadger)
- [Rollbar](#rollbar)
You can also add [custom integrations](#custom-integrations).
### Active Record
Active Record has the option to add comments to queries.
```sql
SELECT ...
/*application:MyApp,controller:posts,action:index,owner:logistics*/
```
Add to `config/application.rb`:
```ruby
config.active_record.query_log_tags_enabled = true
config.active_record.query_log_tags << :owner
```
### AppSignal
The [AppSignal gem integrates with Ownership](https://docs.appsignal.com/ruby/integrations/ownership.html) automatically. Error and performance samples in AppSignal will be tagged with the specified owner.
You can set AppSignal's [`ownership_set_namespace` configuration option](https://docs.appsignal.com/ruby/configuration/options.html#option-ownership_set_namespace) to `true` in order to use the specified owner as an AppSignal namespace, which allows you to easily list performance actions and error incidents for each namespace.
### Honeybadger
[Honeybadger](https://github.com/honeybadger-io/honeybadger-ruby) tracks exceptions. This integration makes it easy to send exceptions to different projects based on the owner. We recommend having a project for each team.
```ruby
Ownership::Honeybadger.api_keys = {
logistics: "token1",
customers: "token2"
}
```
Also works with a proc
```ruby
Ownership::Honeybadger.api_keys = ->(owner) { ENV["#{owner.to_s.upcase}_HONEYBADGER_API_KEY"] }
```
### Rollbar
[Rollbar](https://github.com/rollbar/rollbar-gem) tracks exceptions. This integration makes it easy to send exceptions to different projects based on the owner. We recommend having a project for each team.
```ruby
Ownership::Rollbar.access_token = {
logistics: "token1",
customers: "token2"
}
```
Also works with a proc
```ruby
Ownership::Rollbar.access_token = ->(owner) { ENV["#{owner.to_s.upcase}_ROLLBAR_ACCESS_TOKEN"] }
```
For version 3.1+ of the `rollbar` gem, add to `config/initializers/rollbar.rb`:
```ruby
config.use_payload_access_token = true
```
## Custom Integrations
You can define a custom block of code to run with:
```ruby
Ownership.around_change = proc do |owner, block|
puts "New owner: #{owner}"
block.call
puts "Done"
end
```
Exceptions that bubble up from an `owner` block have the owner, which your exception reporting library can use.
```ruby
begin
owner :logistics do
raise "error"
end
rescue => e
puts e.owner # :logistics
end
```
## Other Useful Tools
- [GitHub Code Owners](https://github.com/blog/2392-introducing-code-owners) for code reviews
## Thanks
Thanks to [Nick Elser](https://github.com/nickelser) for creating this pattern.
## History
View the [changelog](https://github.com/ankane/ownership/blob/master/CHANGELOG.md)
## Contributing
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- [Report bugs](https://github.com/ankane/ownership/issues)
- Fix bugs and [submit pull requests](https://github.com/ankane/ownership/pulls)
- Write, clarify, or fix documentation
- Suggest or add new features
To get started with development and testing:
```sh
git clone https://github.com/ankane/ownership.git
cd ownership
bundle install
bundle exec rake test
```