ownership 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +16 -1
- data/LICENSE.txt +22 -0
- data/README.md +63 -4
- data/lib/ownership/global_methods.rb +9 -2
- data/lib/ownership/honeybadger.rb +47 -0
- data/lib/ownership/version.rb +1 -1
- data/lib/ownership.rb +6 -1
- metadata +16 -89
- data/.gitignore +0 -9
- data/Gemfile +0 -4
- data/Rakefile +0 -11
- data/ownership.gemspec +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c82864cfbec98aec876ca43197e865d246e6dad17187844c4024fc46af6b81f2
|
4
|
+
data.tar.gz: 04e54a16dfce05d2ff93a789edd861df94af852950439c7a3a8ba65506aa610d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56da0f7adfacf7fc289ceddc5fb0061d7b138539158fc7769081755b8f9d7af2020853212b544554708f62a67547852c93297487dff9f0fe7adeee11c973d7b7
|
7
|
+
data.tar.gz: 457826075fb853877bc3940bb0cc3364807983a42fe0ec29a0cd66e732186e03b7cb5534a643d785d87fb1e9a4341d926533b49e72babb2ccd1d34f88b7fc5d7
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
-
## 0.
|
1
|
+
## 0.2.0 (2022-04-26)
|
2
|
+
|
3
|
+
- Fixed issue with nested `owner` blocks
|
4
|
+
- Dropped support for Ruby < 2.6
|
5
|
+
|
6
|
+
## 0.1.2 (2022-03-11)
|
7
|
+
|
8
|
+
- Added Active Record query log tags integration
|
9
|
+
|
10
|
+
## 0.1.1 (2019-10-27)
|
11
|
+
|
12
|
+
- Added Honeybadger integration
|
13
|
+
- Made `owner` method private to behave like `Kernel` methods
|
14
|
+
- Fixed conflict with Pry
|
15
|
+
|
16
|
+
## 0.1.0 (2017-11-05)
|
2
17
|
|
3
18
|
- First release
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2017-2022 Andrew Kane
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
# Ownership
|
2
2
|
|
3
|
-
Code ownership for
|
3
|
+
Code ownership for Rails
|
4
|
+
|
5
|
+
Check out [Scaling the Monolith](https://ankane.org/scaling-the-monolith) for other tips
|
4
6
|
|
5
7
|
:tangerine: Battle-tested at [Instacart](https://www.instacart.com/opensource)
|
6
8
|
|
9
|
+
[![Build Status](https://github.com/ankane/ownership/workflows/build/badge.svg?branch=master)](https://github.com/ankane/ownership/actions)
|
10
|
+
|
7
11
|
## Installation
|
8
12
|
|
9
13
|
Add this line to your application’s Gemfile:
|
10
14
|
|
11
15
|
```ruby
|
12
|
-
gem
|
16
|
+
gem "ownership"
|
13
17
|
```
|
14
18
|
|
15
19
|
## Getting Started
|
@@ -63,9 +67,49 @@ Ownership.default_owner = :logistics
|
|
63
67
|
|
64
68
|
There are a few built-in integrations with other gems.
|
65
69
|
|
70
|
+
- [Active Record](#active-record)
|
71
|
+
- [Honeybadger](#honeybadger)
|
72
|
+
- [Marginalia](#marginalia)
|
73
|
+
- [Rollbar](#rollbar)
|
74
|
+
|
75
|
+
You can also add [custom integrations](#custom-integrations).
|
76
|
+
|
77
|
+
### Active Record
|
78
|
+
|
79
|
+
Active Record 7+ has the option to add comments to queries.
|
80
|
+
|
81
|
+
```sql
|
82
|
+
SELECT ...
|
83
|
+
/*application:MyApp,controller:posts,action:index,owner:logistics*/
|
84
|
+
```
|
85
|
+
|
86
|
+
Add to `config/application.rb`:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
config.active_record.query_log_tags_enabled = true
|
90
|
+
config.active_record.query_log_tags << :owner
|
91
|
+
```
|
92
|
+
|
93
|
+
### Honeybadger
|
94
|
+
|
95
|
+
[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.
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
Ownership::Honeybadger.api_keys = {
|
99
|
+
logistics: "token1",
|
100
|
+
customers: "token2"
|
101
|
+
}
|
102
|
+
```
|
103
|
+
|
104
|
+
Also works with a proc
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
Ownership::Honeybadger.api_keys = ->(owner) { ENV["#{owner.to_s.upcase}_HONEYBADGER_API_KEY"] }
|
108
|
+
```
|
109
|
+
|
66
110
|
### Marginalia
|
67
111
|
|
68
|
-
[Marginalia](https://github.com/basecamp/marginalia) adds comments to
|
112
|
+
[Marginalia](https://github.com/basecamp/marginalia) adds comments to Active Record queries. If installed, the owner is added.
|
69
113
|
|
70
114
|
```sql
|
71
115
|
SELECT ...
|
@@ -88,7 +132,13 @@ Ownership::Rollbar.access_token = {
|
|
88
132
|
Also works with a proc
|
89
133
|
|
90
134
|
```ruby
|
91
|
-
Ownership::Rollbar.access_token = ->
|
135
|
+
Ownership::Rollbar.access_token = ->(owner) { ENV["#{owner.to_s.upcase}_ROLLBAR_ACCESS_TOKEN"] }
|
136
|
+
```
|
137
|
+
|
138
|
+
For version 3.1+ of the `rollbar` gem, add to `config/initializers/rollbar.rb`:
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
config.use_payload_access_token = true
|
92
142
|
```
|
93
143
|
|
94
144
|
## Custom Integrations
|
@@ -137,3 +187,12 @@ Everyone is encouraged to help improve this project. Here are a few ways you can
|
|
137
187
|
- Fix bugs and [submit pull requests](https://github.com/ankane/ownership/pulls)
|
138
188
|
- Write, clarify, or fix documentation
|
139
189
|
- Suggest or add new features
|
190
|
+
|
191
|
+
To get started with development and testing:
|
192
|
+
|
193
|
+
```sh
|
194
|
+
git clone https://github.com/ankane/ownership.git
|
195
|
+
cd ownership
|
196
|
+
bundle install
|
197
|
+
bundle exec rake test
|
198
|
+
```
|
@@ -1,6 +1,13 @@
|
|
1
1
|
module Ownership
|
2
2
|
module GlobalMethods
|
3
|
-
|
3
|
+
private
|
4
|
+
|
5
|
+
def owner(*args, &block)
|
6
|
+
return super if is_a?(Method) # hack for pry
|
7
|
+
|
8
|
+
owner = args[0]
|
9
|
+
# same error message as Ruby
|
10
|
+
raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 1)" if args.size != 1
|
4
11
|
raise ArgumentError, "Missing block" unless block_given?
|
5
12
|
|
6
13
|
previous_value = Thread.current[:ownership_owner]
|
@@ -15,7 +22,7 @@ module Ownership
|
|
15
22
|
block.call
|
16
23
|
end
|
17
24
|
rescue Exception => e
|
18
|
-
e.owner
|
25
|
+
e.owner ||= owner
|
19
26
|
raise
|
20
27
|
end
|
21
28
|
ensure
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Ownership
|
2
|
+
module Honeybadger
|
3
|
+
class << self
|
4
|
+
attr_reader :api_keys
|
5
|
+
|
6
|
+
def api_keys=(api_keys)
|
7
|
+
@api_keys = api_keys
|
8
|
+
@configuration ||= configure
|
9
|
+
api_keys
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def add_owner_as_tag(notice, current_owner)
|
15
|
+
return unless current_owner
|
16
|
+
|
17
|
+
notice.tags << current_owner.to_s
|
18
|
+
end
|
19
|
+
|
20
|
+
def configure
|
21
|
+
::Honeybadger.configure do |config|
|
22
|
+
config.before_notify do |notice|
|
23
|
+
current_owner = notice.exception.owner if notice.exception.is_a?(Exception)
|
24
|
+
current_owner ||= Ownership.owner
|
25
|
+
|
26
|
+
add_owner_as_tag(notice, current_owner)
|
27
|
+
use_owner_api_key(notice, current_owner)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def owner_api_key(current_owner)
|
33
|
+
api_keys.respond_to?(:call) ? api_keys.call(current_owner) : api_keys[current_owner]
|
34
|
+
end
|
35
|
+
|
36
|
+
def use_owner_api_key(notice, current_owner)
|
37
|
+
return unless current_owner
|
38
|
+
|
39
|
+
if (api_key = owner_api_key(current_owner))
|
40
|
+
notice.api_key = api_key
|
41
|
+
else
|
42
|
+
warn "[ownership] Missing Honeybadger API key for owner: #{current_owner}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/ownership/version.rb
CHANGED
data/lib/ownership.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "ownership/global_methods"
|
2
|
+
require "ownership/honeybadger"
|
2
3
|
require "ownership/rollbar"
|
3
4
|
require "ownership/version"
|
4
5
|
|
@@ -13,7 +14,7 @@ module Ownership
|
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
|
-
Object.
|
17
|
+
Object.include Ownership::GlobalMethods
|
17
18
|
|
18
19
|
if defined?(ActiveSupport)
|
19
20
|
ActiveSupport.on_load(:action_controller) do
|
@@ -22,6 +23,10 @@ if defined?(ActiveSupport)
|
|
22
23
|
end
|
23
24
|
|
24
25
|
ActiveSupport.on_load(:active_record) do
|
26
|
+
if ActiveRecord::VERSION::MAJOR >= 7
|
27
|
+
ActiveRecord::QueryLogs.taggings[:owner] ||= -> { Ownership.owner }
|
28
|
+
end
|
29
|
+
|
25
30
|
require "ownership/marginalia" if defined?(Marginalia)
|
26
31
|
end
|
27
32
|
|
metadata
CHANGED
@@ -1,109 +1,37 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ownership
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
|
-
autorequire:
|
9
|
-
bindir:
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: minitest
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: activejob
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: marginalia
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
description:
|
84
|
-
email:
|
85
|
-
- andrew@chartkick.com
|
11
|
+
date: 2022-04-26 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: andrew@ankane.org
|
86
15
|
executables: []
|
87
16
|
extensions: []
|
88
17
|
extra_rdoc_files: []
|
89
18
|
files:
|
90
|
-
- ".gitignore"
|
91
19
|
- CHANGELOG.md
|
92
|
-
-
|
20
|
+
- LICENSE.txt
|
93
21
|
- README.md
|
94
|
-
- Rakefile
|
95
22
|
- lib/ownership.rb
|
96
23
|
- lib/ownership/controller_methods.rb
|
97
24
|
- lib/ownership/global_methods.rb
|
25
|
+
- lib/ownership/honeybadger.rb
|
98
26
|
- lib/ownership/job_methods.rb
|
99
27
|
- lib/ownership/marginalia.rb
|
100
28
|
- lib/ownership/rollbar.rb
|
101
29
|
- lib/ownership/version.rb
|
102
|
-
- ownership.gemspec
|
103
30
|
homepage: https://github.com/ankane/ownership
|
104
|
-
licenses:
|
31
|
+
licenses:
|
32
|
+
- MIT
|
105
33
|
metadata: {}
|
106
|
-
post_install_message:
|
34
|
+
post_install_message:
|
107
35
|
rdoc_options: []
|
108
36
|
require_paths:
|
109
37
|
- lib
|
@@ -111,16 +39,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
39
|
requirements:
|
112
40
|
- - ">="
|
113
41
|
- !ruby/object:Gem::Version
|
114
|
-
version: '
|
42
|
+
version: '2.6'
|
115
43
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
44
|
requirements:
|
117
45
|
- - ">="
|
118
46
|
- !ruby/object:Gem::Version
|
119
47
|
version: '0'
|
120
48
|
requirements: []
|
121
|
-
|
122
|
-
|
123
|
-
signing_key:
|
49
|
+
rubygems_version: 3.3.7
|
50
|
+
signing_key:
|
124
51
|
specification_version: 4
|
125
|
-
summary: Code ownership for
|
52
|
+
summary: Code ownership for Rails
|
126
53
|
test_files: []
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
data/ownership.gemspec
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "ownership/version"
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "ownership"
|
8
|
-
spec.version = Ownership::VERSION
|
9
|
-
spec.authors = ["Andrew Kane"]
|
10
|
-
spec.email = ["andrew@chartkick.com"]
|
11
|
-
|
12
|
-
spec.summary = "Code ownership for your Rails app"
|
13
|
-
spec.homepage = "https://github.com/ankane/ownership"
|
14
|
-
|
15
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
-
f.match(%r{^(test|spec|features)/})
|
17
|
-
end
|
18
|
-
spec.bindir = "exe"
|
19
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = ["lib"]
|
21
|
-
|
22
|
-
spec.add_development_dependency "bundler"
|
23
|
-
spec.add_development_dependency "rake"
|
24
|
-
spec.add_development_dependency "minitest"
|
25
|
-
spec.add_development_dependency "activejob"
|
26
|
-
spec.add_development_dependency "marginalia"
|
27
|
-
end
|