action_reporter 1.4.1 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd1a58fef3515e786a32bfea51175eb11f081f09773fe6476de0868ca01fa76c
4
- data.tar.gz: 4b3953a48e8e34fecbf48ce7068836b228aec8d52f83ef8926667b74e679f4eb
3
+ metadata.gz: 310122c609e9af5d1ea9196fa5596a5c3b2d21b951c347a35983fb6ccbf47fe3
4
+ data.tar.gz: c9beb3493e8b36bd7c8da57850da96e1fb4e4465c4f9293c2f4a8262fdf79a91
5
5
  SHA512:
6
- metadata.gz: f9e273e313f21642a7dcc6517c4b38f977a30e41c50928c0b936ded0ac88fc76bbd031e0f9a8f5c3c7bdf9b87991c0e51d5e9af3e3c85b9c7baae8f01e09584e
7
- data.tar.gz: 6e3c58d80555fd4487cac9d057eafc2960d1e35028f1a4f772ee05586b625d1e4e8ceabe028776833578334e2a8a2213a13fef55f0e82fe7219818d7a0056181
6
+ metadata.gz: b660e58bb8fba800eaebba9566e22df001e4b8111883bc917078c72c95ef19e5cad38557109ff8a397d56b5503c416122abccb8219d22169fdbf9222a592e596
7
+ data.tar.gz: 3eed255cb5337162b9785f5c89205de4eb9f1942f6bf7a6c7282080f63ef9b1bf84bb0288a784f12f4b4e7b36a580de1d4cda7eb74e5f8d8fe72f3d7bbbf38c7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ # 1.5.1
2
+
3
+ * Fix Audited current user setter to use `audited_user`
4
+
5
+ # 1.5.0
6
+
7
+ * BREAKING: Rename `audited_user` to `current_user`
8
+ * Add `current_request_uuid` and `current_remote_addr` getters and setters
9
+ * Memoize `current_user`, `current_request_uuid`, and `current_remote_addr`
10
+
1
11
  # 1.4.1
2
12
 
3
13
  * Add paper_trail support
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/action_reporter.svg)](https://badge.fury.io/rb/action_reporter) [![Test Status](https://github.com/amkisko/action_reporter.rb/actions/workflows/test.yml/badge.svg)](https://github.com/amkisko/action_reporter.rb/actions/workflows/test.yml) [![codecov](https://codecov.io/gh/amkisko/action_reporter.rb/graph/badge.svg?token=JCV2A7NWTE)](https://codecov.io/gh/amkisko/action_reporter.rb)
4
4
 
5
+ [![Codacy Badge](https://app.codacy.com/project/badge/Grade/f4bef9a52eac43a5a0f6d8c1b58cc6af)](https://app.codacy.com/gh/amkisko/action_reporter.rb/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/f4bef9a52eac43a5a0f6d8c1b58cc6af)](https://app.codacy.com/gh/amkisko/action_reporter.rb/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
6
+
5
7
  Ruby wrapper for multiple reporting services.
6
8
 
7
9
  Supported services:
@@ -50,11 +52,28 @@ ActionReporter.enabled_reporters = [
50
52
  Then you can use it in your code:
51
53
 
52
54
  ```ruby
53
- ActionReporter.audited_user = current_user
55
+ ActionReporter.current_user = current_user
56
+ ActionReporter.current_request_uuid = request.env['action_dispatch.request_id']
57
+ ActionReporter.current_remote_addr = request.env['action_dispatch.remote_ip']
54
58
  ActionReporter.context(entry_id: entry.id)
55
59
  ActionReporter.notify('Something went wrong', context: { record: record })
56
60
  ```
57
61
 
62
+ ## Hook debugger to notify method
63
+
64
+ Apply patch on initializer level or before running the main code:
65
+
66
+ ```ruby
67
+ module ActionReporter
68
+ class RailsReporter < Base
69
+ def notify(error, context: {})
70
+ super
71
+ binding.pry
72
+ end
73
+ end
74
+ end
75
+ ```
76
+
58
77
  ## Contributing
59
78
 
60
79
  Bug reports and pull requests are welcome on GitHub at https://github.com/amkisko/action_reporter.rb
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "action_reporter"
3
- gem.version = File.read(File.expand_path('../lib/action_reporter.rb', __FILE__)).match(/VERSION\s*=\s*'(.*?)'/)[1]
3
+ gem.version = File.read(File.expand_path("../lib/action_reporter.rb", __FILE__)).match(/VERSION\s*=\s*'(.*?)'/)[1]
4
4
 
5
5
  gem.license = "MIT"
6
6
 
@@ -21,7 +21,7 @@ Gem::Specification.new do |gem|
21
21
  "rubygems_mfa_required" => "true"
22
22
  }
23
23
 
24
- gem.files = Dir.glob("lib/**/*.rb") + Dir.glob("bin/**/*") + %w(CHANGELOG.md LICENSE.md README.md action_reporter.gemspec)
24
+ gem.files = Dir.glob("lib/**/*.rb") + Dir.glob("bin/**/*") + %w[CHANGELOG.md LICENSE.md README.md action_reporter.gemspec]
25
25
 
26
26
  # s.bindir = "bin"
27
27
  # s.executables = ["action_reporter"]
@@ -29,17 +29,17 @@ Gem::Specification.new do |gem|
29
29
  gem.required_ruby_version = ">= 2.5.0"
30
30
  gem.require_path = "lib"
31
31
 
32
- gem.add_runtime_dependency 'rails', '> 5'
32
+ gem.add_runtime_dependency "rails", "> 5"
33
33
 
34
- gem.add_development_dependency 'audited', '~> 5'
35
- gem.add_development_dependency 'honeybadger', '~> 5'
36
- gem.add_development_dependency 'sentry-ruby', '~> 5'
37
- gem.add_development_dependency 'scout_apm', '~> 5'
38
- gem.add_development_dependency 'paper_trail', '~> 15'
34
+ gem.add_development_dependency "audited", "~> 5"
35
+ gem.add_development_dependency "honeybadger", "~> 5"
36
+ gem.add_development_dependency "sentry-ruby", "~> 5"
37
+ gem.add_development_dependency "scout_apm", "~> 5"
38
+ gem.add_development_dependency "paper_trail", "~> 15"
39
39
 
40
- gem.add_development_dependency 'rspec', '~> 3'
41
- gem.add_development_dependency 'webmock', '~> 3'
42
- gem.add_development_dependency 'pry', '~> 0.14'
43
- gem.add_development_dependency 'simplecov', '~> 0.21'
44
- gem.add_development_dependency 'simplecov-cobertura', '~> 2'
40
+ gem.add_development_dependency "rspec", "~> 3"
41
+ gem.add_development_dependency "webmock", "~> 3"
42
+ gem.add_development_dependency "pry", "~> 0.14"
43
+ gem.add_development_dependency "simplecov", "~> 0.21"
44
+ gem.add_development_dependency "simplecov-cobertura", "~> 2"
45
45
  end
@@ -6,22 +6,36 @@ module ActionReporter
6
6
  end
7
7
 
8
8
  def context(args)
9
- Audited.store[:current_remote_address] = args[:remote_addr] if args[
10
- :remote_addr
11
- ].present?
12
9
  end
13
10
 
14
11
  def reset_context
15
12
  Audited.store.delete(:current_remote_address)
13
+ Audited.store.delete(:current_request_uuid)
16
14
  Audited.store.delete(:audited_user)
17
15
  end
18
16
 
19
- def audited_user
17
+ def current_user
20
18
  Audited.store[:audited_user]
21
19
  end
22
20
 
23
- def audited_user=(user)
21
+ def current_user=(user)
24
22
  Audited.store[:audited_user] = user
25
23
  end
24
+
25
+ def current_request_uuid
26
+ Audited.store[:current_request_uuid]
27
+ end
28
+
29
+ def current_request_uuid=(request_uuid)
30
+ Audited.store[:current_request_uuid] = request_uuid
31
+ end
32
+
33
+ def current_remote_addr
34
+ Audited.store[:current_remote_address]
35
+ end
36
+
37
+ def current_remote_addr=(remote_addr)
38
+ Audited.store[:current_remote_address] = remote_addr
39
+ end
26
40
  end
27
41
  end
@@ -21,7 +21,7 @@ module ActionReporter
21
21
  honeybadger_class.check_in(check_in_id)
22
22
  end
23
23
 
24
- def audited_user=(user)
24
+ def current_user=(user)
25
25
  honeybadger_class.context(user_global_id: user.to_global_id.to_s) if user
26
26
  end
27
27
  end
@@ -12,11 +12,11 @@ module ActionReporter
12
12
  PaperTrail.request.whodunnit = nil
13
13
  end
14
14
 
15
- def audited_user
15
+ def current_user
16
16
  PaperTrail.request.whodunnit
17
17
  end
18
18
 
19
- def audited_user=(user)
19
+ def current_user=(user)
20
20
  PaperTrail.request.whodunnit = user
21
21
  end
22
22
  end
@@ -13,8 +13,12 @@ module ActionReporter
13
13
  scoutapm_context_class.add(new_context)
14
14
  end
15
15
 
16
- def audited_user=(user)
16
+ def current_user=(user)
17
17
  scoutapm_context_class.add_user(user_global_id: user&.to_global_id&.to_s)
18
18
  end
19
+
20
+ def ignore_transaction!
21
+ scoutapm_context_class.ignore_transaction!
22
+ end
19
23
  end
20
24
  end
@@ -22,7 +22,7 @@ module ActionReporter
22
22
  sentry_class.get_current_scope.set_context("context", {})
23
23
  end
24
24
 
25
- def audited_user=(user)
25
+ def current_user=(user)
26
26
  sentry_class.set_user(user_global_id: user&.to_global_id&.to_s)
27
27
  end
28
28
  end
@@ -10,7 +10,7 @@ require 'action_reporter/paper_trail_reporter'
10
10
  module ActionReporter
11
11
  module_function
12
12
 
13
- VERSION = '1.4.1'.freeze
13
+ VERSION = '1.5.1'.freeze
14
14
 
15
15
  AVAILABLE_REPORTERS = [
16
16
  ActionReporter::RailsReporter,
@@ -55,15 +55,42 @@ module ActionReporter
55
55
  end
56
56
  end
57
57
 
58
- def audited_user
59
- enabled_reporters.find { |r| r.respond_to?(:audited_user) }&.audited_user
58
+ def current_user
59
+ @current_user
60
60
  end
61
61
 
62
- def audited_user=(user)
62
+ def current_user=(user)
63
+ @current_user = user
63
64
  enabled_reporters.each do |reporter|
64
- next unless reporter.respond_to?(:audited_user=)
65
+ next unless reporter.respond_to?(:current_user=)
65
66
 
66
- reporter.audited_user = user
67
+ reporter.current_user = user
68
+ end
69
+ end
70
+
71
+ def current_request_uuid
72
+ @current_request_uuid
73
+ end
74
+
75
+ def current_request_uuid=(request_uuid)
76
+ @current_request_uuid = request_uuid
77
+ enabled_reporters.each do |reporter|
78
+ next unless reporter.respond_to?(:current_request_uuid=)
79
+
80
+ reporter.current_request_uuid = request_uuid
81
+ end
82
+ end
83
+
84
+ def current_remote_addr
85
+ @current_remote_addr
86
+ end
87
+
88
+ def current_remote_addr=(remote_addr)
89
+ @current_remote_addr = remote_addr
90
+ enabled_reporters.each do |reporter|
91
+ next unless reporter.respond_to?(:current_remote_addr=)
92
+
93
+ reporter.current_remote_addr = remote_addr
67
94
  end
68
95
  end
69
96
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_reporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Makarov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-02 00:00:00.000000000 Z
11
+ date: 2024-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -209,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
209
  - !ruby/object:Gem::Version
210
210
  version: '0'
211
211
  requirements: []
212
- rubygems_version: 3.4.19
212
+ rubygems_version: 3.5.11
213
213
  signing_key:
214
214
  specification_version: 4
215
215
  summary: See description