rails_band 0.7.0 → 0.8.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: b9edf37b23613a1499389b5c70ba7c1e80112ab6b8f8879d4983c26ed41092e5
4
- data.tar.gz: aded5c59846b0f4befa0ad2bca8dd48b63f37af95adedd5bb38ae672bafd001e
3
+ metadata.gz: a7d219290781013be7ed31f2f197662a035ef2269fcf79056863d0727dc03315
4
+ data.tar.gz: 2be225e5abdcb68791f0cee3f06617b217c720f7f3142fced02ea8777fc402bc
5
5
  SHA512:
6
- metadata.gz: fecc6a2eca4835e5717e1fbe2aff99f29f585dc091215d1be8a8d2455fc8fec664da2a50f61535d906b68e4429ea5a5acf45a27a7a10840115558302575b0bc8
7
- data.tar.gz: 1a0986674189d1546bba3988b0271496bf006b83fc86a894a676dd9c97d8f5efa7b7a84d7b6e488efe55fdf0e97d016168c99ff8d47a92b5fa56b3b08a5d8b28
6
+ metadata.gz: 8a4bee2d71d4facf2aae5e0ba560b650faafebabfe7d015bb36db789c0ced97e8cc449b8433eb2a8dae1fc21a313d95b09eb09ccf34f649987caf8d4b97dee3a
7
+ data.tar.gz: 006eddea4ad5bf2f07f93264faa13ee4bdf6b2335652106bc2e1b2f84ea3d6db61a033103238d97ddc35bbbeb1ae46192902fe6e6c715ce621602c6f0224d1fe
data/README.md CHANGED
@@ -73,7 +73,8 @@ These are Rails Instrumentation API hooks supported by this gem so far.
73
73
 
74
74
  | Event name | Supported |
75
75
  | --------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
76
- | [`process_middleware.action_dispatch`](https://guides.rubyonrails.org/active_support_instrumentation.html#process-middleware-action-dispatch) | |
76
+ | [`process_middleware.action_dispatch`](https://guides.rubyonrails.org/active_support_instrumentation.html#process-middleware-action-dispatch) ||
77
+ | [`redirect.action_dispatch`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#redirect-action-dispatch) | ✅ |
77
78
 
78
79
  ### Action View
79
80
 
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActionDispatch
5
+ module Event
6
+ # A wrapper for the event that is passed to `process_middleware.action_dispatch`.
7
+ class ProcessMiddleware < BaseEvent
8
+ def middleware
9
+ @middleware ||= @event.payload.fetch(:middleware)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActionDispatch
5
+ module Event
6
+ # A wrapper for the event that is passed to `redirect.action_dispatch`.
7
+ class Redirect < BaseEvent
8
+ def status
9
+ @status ||= @event.payload.fetch(:status)
10
+ end
11
+
12
+ def location
13
+ @location ||= @event.payload.fetch(:location)
14
+ end
15
+
16
+ def request
17
+ @request ||= @event.payload.fetch(:request)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_band/action_dispatch/event/process_middleware'
4
+ require 'rails_band/action_dispatch/event/redirect'
5
+
6
+ module RailsBand
7
+ module ActionDispatch
8
+ # The custom LogSubscriber for ActionDispatch.
9
+ class LogSubscriber < ::ActiveSupport::LogSubscriber
10
+ mattr_accessor :consumers
11
+
12
+ def process_middleware(event)
13
+ consumer_of(__method__)&.call(Event::ProcessMiddleware.new(event))
14
+ end
15
+
16
+ def redirect(event)
17
+ consumer_of(__method__)&.call(Event::Redirect.new(event))
18
+ end
19
+
20
+ private
21
+
22
+ def consumer_of(sub_event)
23
+ consumers[:"#{sub_event}.action_dispatch"] || consumers[:action_dispatch] || consumers[:default]
24
+ end
25
+ end
26
+ end
27
+ end
@@ -22,6 +22,12 @@ module RailsBand
22
22
  def cache_hit
23
23
  @cache_hit ||= @event.payload.fetch(:cache_hit)
24
24
  end
25
+
26
+ if Gem::Version.new(Rails.version) >= Gem::Version.new('7.1.0.alpha')
27
+ define_method(:locals) do
28
+ @locals ||= @event.payload[:locals]
29
+ end
30
+ end
25
31
  end
26
32
  end
27
33
  end
@@ -18,6 +18,12 @@ module RailsBand
18
18
 
19
19
  @layout = @event.payload[:layout]&.then { |layout| from_views(layout) }
20
20
  end
21
+
22
+ if Gem::Version.new(Rails.version) >= Gem::Version.new('7.1.0.alpha')
23
+ define_method(:locals) do
24
+ @locals ||= @event.payload[:locals]
25
+ end
26
+ end
21
27
  end
22
28
  end
23
29
  end
@@ -13,7 +13,7 @@ module RailsBand
13
13
  @job ||= @event.payload.fetch(:job)
14
14
  end
15
15
 
16
- if Gem::Version.new(Rails.version) > Gem::Version.new('7.0')
16
+ if Gem::Version.new(Rails.version) >= Gem::Version.new('7.1.0.alpha')
17
17
  define_method(:aborted) do
18
18
  return @aborted if defined?(@aborted)
19
19
 
@@ -13,7 +13,7 @@ module RailsBand
13
13
  @job ||= @event.payload.fetch(:job)
14
14
  end
15
15
 
16
- if Gem::Version.new(Rails.version) > Gem::Version.new('7.0')
16
+ if Gem::Version.new(Rails.version) >= Gem::Version.new('7.1.0.alpha')
17
17
  define_method(:aborted) do
18
18
  return @aborted if defined?(@aborted)
19
19
 
@@ -13,12 +13,16 @@ module RailsBand
13
13
  @job ||= @event.payload.fetch(:job)
14
14
  end
15
15
 
16
- if Gem::Version.new(Rails.version) > Gem::Version.new('7.0')
16
+ if Gem::Version.new(Rails.version) >= Gem::Version.new('7.1.0.alpha')
17
17
  define_method(:aborted) do
18
18
  return @aborted if defined?(@aborted)
19
19
 
20
20
  @aborted = @event.payload[:aborted]
21
21
  end
22
+
23
+ define_method(:db_runtime) do
24
+ @db_runtime ||= @event.payload[:db_runtime]
25
+ end
22
26
  end
23
27
  end
24
28
  end
@@ -8,6 +8,14 @@ module RailsBand
8
8
  class Railtie < ::Rails::Railtie
9
9
  config.rails_band = Configuration.new
10
10
 
11
+ config.before_initialize do
12
+ # NOTE: `ActionDispatch::MiddlewareStack::InstrumentationProxy` will be called
13
+ # only when `ActionDispatch::MiddlewareStack#build` detects `process_middleware.action_dispatch`
14
+ # is listened to. So, `attach_to` must be called before Rack middlewares will be loaded.
15
+ ::ActionDispatch::LogSubscriber.detach_from :action_dispatch if defined?(::ActionDispatch::LogSubscriber)
16
+ RailsBand::ActionDispatch::LogSubscriber.attach_to :action_dispatch
17
+ end
18
+
11
19
  config.after_initialize do |app|
12
20
  consumers = app.config.rails_band.consumers
13
21
 
@@ -40,6 +48,8 @@ module RailsBand
40
48
  RailsBand::ActiveStorage::LogSubscriber.attach_to :active_storage
41
49
  end
42
50
 
51
+ RailsBand::ActionDispatch::LogSubscriber.consumers = consumers
52
+
43
53
  RailsBand::ActiveSupport::LogSubscriber.consumers = consumers
44
54
  RailsBand::ActiveSupport::LogSubscriber.attach_to :active_support
45
55
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsBand
4
- VERSION = '0.7.0'
4
+ VERSION = '0.8.1'
5
5
  end
data/lib/rails_band.rb CHANGED
@@ -9,34 +9,47 @@ require 'rails_band/railtie'
9
9
  # Rails::Band unsubscribes all default LogSubscribers from Rails Instrumentation API,
10
10
  # and it subscribes our own custom LogSubscribers to make it easy to access Rails Instrumentation API.
11
11
  module RailsBand
12
+ # RailsBand::ActionController is responsible for subscribing notifications from ActionController.
12
13
  module ActionController
13
14
  autoload :LogSubscriber, 'rails_band/action_controller/log_subscriber'
14
15
  end
15
16
 
17
+ # RailsBand::ActionView is responsible for subscribing notifications from ActionView.
16
18
  module ActionView
17
19
  autoload :LogSubscriber, 'rails_band/action_view/log_subscriber'
18
20
  end
19
21
 
22
+ # RailsBand::ActiveRecord is responsible for subscribing notifications from ActiveRecord.
20
23
  module ActiveRecord
21
24
  autoload :LogSubscriber, 'rails_band/active_record/log_subscriber'
22
25
  end
23
26
 
27
+ # RailsBand::ActionMailer is responsible for subscribing notifications from ActionMailer.
24
28
  module ActionMailer
25
29
  autoload :LogSubscriber, 'rails_band/action_mailer/log_subscriber'
26
30
  end
27
31
 
32
+ # RailsBand::ActionDispatch is responsible for subscribing notifications from ActionDispatch.
33
+ module ActionDispatch
34
+ autoload :LogSubscriber, 'rails_band/action_dispatch/log_subscriber'
35
+ end
36
+
37
+ # RailsBand::ActiveSupport is responsible for subscribing notifications from ActiveSupport.
28
38
  module ActiveSupport
29
39
  autoload :LogSubscriber, 'rails_band/active_support/log_subscriber'
30
40
  end
31
41
 
42
+ # RailsBand::ActiveJob is responsible for subscribing notifications from ActiveJob.
32
43
  module ActiveJob
33
44
  autoload :LogSubscriber, 'rails_band/active_job/log_subscriber'
34
45
  end
35
46
 
47
+ # RailsBand::ActionCable is responsible for subscribing notifications from ActionCable.
36
48
  module ActionCable
37
49
  autoload :LogSubscriber, 'rails_band/action_cable/log_subscriber'
38
50
  end
39
51
 
52
+ # RailsBand::ActiveStorage is responsible for subscribing notifications from ActiveStorage.
40
53
  module ActiveStorage
41
54
  autoload :LogSubscriber, 'rails_band/active_storage/log_subscriber'
42
55
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_band
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yutaka Kamei
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-31 00:00:00.000000000 Z
11
+ date: 2023-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -59,6 +59,9 @@ files:
59
59
  - lib/rails_band/action_controller/event/unpermitted_parameters.rb
60
60
  - lib/rails_band/action_controller/event/write_fragment.rb
61
61
  - lib/rails_band/action_controller/log_subscriber.rb
62
+ - lib/rails_band/action_dispatch/event/process_middleware.rb
63
+ - lib/rails_band/action_dispatch/event/redirect.rb
64
+ - lib/rails_band/action_dispatch/log_subscriber.rb
62
65
  - lib/rails_band/action_mailer/event/deliver.rb
63
66
  - lib/rails_band/action_mailer/event/process.rb
64
67
  - lib/rails_band/action_mailer/log_subscriber.rb
@@ -114,7 +117,6 @@ licenses:
114
117
  metadata:
115
118
  homepage_uri: https://github.com/yykamei/rails_band
116
119
  source_code_uri: https://github.com/yykamei/rails_band
117
- changelog_uri: https://github.com/yykamei/rails_band/blob/main/CHANGELOG.md
118
120
  rubygems_mfa_required: 'true'
119
121
  post_install_message:
120
122
  rdoc_options: []
@@ -131,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
133
  - !ruby/object:Gem::Version
132
134
  version: '0'
133
135
  requirements: []
134
- rubygems_version: 3.3.7
136
+ rubygems_version: 3.4.6
135
137
  signing_key:
136
138
  specification_version: 4
137
139
  summary: Easy-to-use Rails Instrumentation API