rails_band 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33531dca2bfc581e2d892bfa6962bb31d41e1fef075917a8cb4427ed6b65c2e5
4
- data.tar.gz: a4f5af5171bf836e9071cddffe9b06654eba3538c58b0bf7c5bbde93587e0686
3
+ metadata.gz: b9edf37b23613a1499389b5c70ba7c1e80112ab6b8f8879d4983c26ed41092e5
4
+ data.tar.gz: aded5c59846b0f4befa0ad2bca8dd48b63f37af95adedd5bb38ae672bafd001e
5
5
  SHA512:
6
- metadata.gz: fc3c5c8628d6e8a0bb963e257d6eaa1c2cd8278b71f477034d33ea715c2563efe8854b466daa3aa9dadce94da15840ca2f4e65ee49fdfb0a30fa9880d20365ed
7
- data.tar.gz: bc5f016c6b62c01b5081a9bc75a882edbcb51e7be37b65fa24ba17ef570855de37e6fdce6c86a1cccbb8d78aa77b2e5f47e077e086e8f138513fd87230e34a1f
6
+ metadata.gz: fecc6a2eca4835e5717e1fbe2aff99f29f585dc091215d1be8a8d2455fc8fec664da2a50f61535d906b68e4429ea5a5acf45a27a7a10840115558302575b0bc8
7
+ data.tar.gz: 1a0986674189d1546bba3988b0271496bf006b83fc86a894a676dd9c97d8f5efa7b7a84d7b6e488efe55fdf0e97d016168c99ff8d47a92b5fa56b3b08a5d8b28
data/README.md CHANGED
@@ -82,7 +82,7 @@ These are Rails Instrumentation API hooks supported by this gem so far.
82
82
  | [`render_template.action_view`](https://guides.rubyonrails.org/active_support_instrumentation.html#render-template-action-view) | ✅ |
83
83
  | [`render_partial.action_view`](https://guides.rubyonrails.org/active_support_instrumentation.html#render-partial-action-view) | ✅ |
84
84
  | [`render_collection.action_view`](https://guides.rubyonrails.org/active_support_instrumentation.html#render-collection-action-view) | ✅ |
85
- | [`render_layout.action_view`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#render-layout-action-view) | |
85
+ | [`render_layout.action_view`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#render-layout-action-view) ||
86
86
 
87
87
  ### Active Record
88
88
 
@@ -162,7 +162,7 @@ These are Rails Instrumentation API hooks supported by this gem so far.
162
162
 
163
163
  | Event name | Supported |
164
164
  | ----------------------------------------------------------------------------------------------------------- | --------- |
165
- | [`deprecation.rails`](https://guides.rubyonrails.org/active_support_instrumentation.html#deprecation-rails) | |
165
+ | [`deprecation.rails`](https://guides.rubyonrails.org/active_support_instrumentation.html#deprecation-rails) ||
166
166
 
167
167
  ## Contributing
168
168
 
@@ -16,7 +16,7 @@ module RailsBand
16
16
  def layout
17
17
  return @layout if defined? @layout
18
18
 
19
- @layout = @event.payload[:layout]&.yield_self { |layout| from_views(layout) }
19
+ @layout = @event.payload[:layout]&.then { |layout| from_views(layout) }
20
20
  end
21
21
 
22
22
  def count
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_band/action_view/from_views'
4
+
5
+ module RailsBand
6
+ module ActionView
7
+ module Event
8
+ # A wrapper for the event that is passed to `render_layout.action_view`.
9
+ class RenderLayout < BaseEvent
10
+ include FromViews
11
+
12
+ def identifier
13
+ @identifier ||= from_views(@event.payload.fetch(:identifier))
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -16,7 +16,7 @@ module RailsBand
16
16
  def layout
17
17
  return @layout if defined? @layout
18
18
 
19
- @layout = @event.payload[:layout]&.yield_self { |layout| from_views(layout) }
19
+ @layout = @event.payload[:layout]&.then { |layout| from_views(layout) }
20
20
  end
21
21
 
22
22
  def cache_hit
@@ -16,7 +16,7 @@ module RailsBand
16
16
  def layout
17
17
  return @layout if defined? @layout
18
18
 
19
- @layout = @event.payload[:layout]&.yield_self { |layout| from_views(layout) }
19
+ @layout = @event.payload[:layout]&.then { |layout| from_views(layout) }
20
20
  end
21
21
  end
22
22
  end
@@ -3,6 +3,7 @@
3
3
  require 'rails_band/action_view/event/render_template'
4
4
  require 'rails_band/action_view/event/render_partial'
5
5
  require 'rails_band/action_view/event/render_collection'
6
+ require 'rails_band/action_view/event/render_layout'
6
7
 
7
8
  module RailsBand
8
9
  module ActionView
@@ -22,6 +23,10 @@ module RailsBand
22
23
  consumer_of(__method__)&.call(Event::RenderCollection.new(event))
23
24
  end
24
25
 
26
+ def render_layout(event)
27
+ consumer_of(__method__)&.call(Event::RenderLayout.new(event))
28
+ end
29
+
25
30
  private
26
31
 
27
32
  def consumer_of(sub_event)
@@ -12,6 +12,14 @@ module RailsBand
12
12
  def job
13
13
  @job ||= @event.payload.fetch(:job)
14
14
  end
15
+
16
+ if Gem::Version.new(Rails.version) > Gem::Version.new('7.0')
17
+ define_method(:aborted) do
18
+ return @aborted if defined?(@aborted)
19
+
20
+ @aborted = @event.payload[:aborted]
21
+ end
22
+ end
15
23
  end
16
24
  end
17
25
  end
@@ -12,6 +12,14 @@ module RailsBand
12
12
  def job
13
13
  @job ||= @event.payload.fetch(:job)
14
14
  end
15
+
16
+ if Gem::Version.new(Rails.version) > Gem::Version.new('7.0')
17
+ define_method(:aborted) do
18
+ return @aborted if defined?(@aborted)
19
+
20
+ @aborted = @event.payload[:aborted]
21
+ end
22
+ end
15
23
  end
16
24
  end
17
25
  end
@@ -12,6 +12,14 @@ module RailsBand
12
12
  def job
13
13
  @job ||= @event.payload.fetch(:job)
14
14
  end
15
+
16
+ if Gem::Version.new(Rails.version) > Gem::Version.new('7.0')
17
+ define_method(:aborted) do
18
+ return @aborted if defined?(@aborted)
19
+
20
+ @aborted = @event.payload[:aborted]
21
+ end
22
+ end
15
23
  end
16
24
  end
17
25
  end
@@ -3,7 +3,7 @@
3
3
  module RailsBand
4
4
  # The base class of each Event class.
5
5
  class BaseEvent
6
- attr_reader :name, :time, :end, :transaction_id, :children,
6
+ attr_reader :name, :time, :end, :transaction_id,
7
7
  :cpu_time, :idle_time, :allocations, :duration
8
8
 
9
9
  # @param event [ActiveSupport::Notifications::Event]
@@ -13,7 +13,6 @@ module RailsBand
13
13
  @time = event.time
14
14
  @end = event.end
15
15
  @transaction_id = event.transaction_id
16
- @children = event.children
17
16
  @cpu_time = event.cpu_time
18
17
  @idle_time = event.idle_time
19
18
  @allocations = event.allocations
@@ -22,7 +21,7 @@ module RailsBand
22
21
 
23
22
  def to_h
24
23
  @to_h ||= {
25
- name: @name, time: @time, end: @end, transaction_id: @transaction_id, children: @children,
24
+ name: @name, time: @time, end: @end, transaction_id: @transaction_id,
26
25
  cpu_time: @cpu_time, idle_time: @idle_time, allocations: @allocations, duration: @duration
27
26
  }.merge!(
28
27
  public_methods(false).reject { |meth| non_hash_keys.include?(meth) }.each_with_object({}) do |meth, h|
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ # DeprecationSubscriber is responsible for logging deprecation warnings.
5
+ class DeprecationSubscriber < ::ActiveSupport::LogSubscriber
6
+ # DeprecationEvent is a wrapper around a deprecation notification event.
7
+ class DeprecationEvent < BaseEvent
8
+ def message
9
+ @message ||= @event.payload.fetch(:message)
10
+ end
11
+
12
+ def callstack
13
+ @callstack ||= @event.payload.fetch(:callstack)
14
+ end
15
+
16
+ def gem_name
17
+ @gem_name ||= @event.payload.fetch(:gem_name)
18
+ end
19
+
20
+ def deprecation_horizon
21
+ @deprecation_horizon ||= @event.payload.fetch(:deprecation_horizon)
22
+ end
23
+ end
24
+
25
+ mattr_accessor :consumers
26
+
27
+ def deprecation(event)
28
+ consumer&.call(DeprecationEvent.new(event))
29
+ end
30
+
31
+ private
32
+
33
+ def consumer
34
+ # HACK: ActiveSupport::Subscriber has the instance variable @namespace, but it's not documented.
35
+ # This hack might possibly break in the future.
36
+ namespace = self.class.instance_variable_get(:@namespace)
37
+ consumers[:"deprecation.#{namespace}"] || consumers[:deprecation] || consumers[:default]
38
+ end
39
+ end
40
+ end
@@ -43,6 +43,9 @@ module RailsBand
43
43
  RailsBand::ActiveSupport::LogSubscriber.consumers = consumers
44
44
  RailsBand::ActiveSupport::LogSubscriber.attach_to :active_support
45
45
 
46
+ RailsBand::DeprecationSubscriber.consumers = consumers
47
+ RailsBand::DeprecationSubscriber.attach_to :rails
48
+
46
49
  if defined?(::ActiveJob)
47
50
  require 'active_job/logging'
48
51
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsBand
4
- VERSION = '0.6.1'
4
+ VERSION = '0.7.0'
5
5
  end
data/lib/rails_band.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'rails_band/version'
4
4
  require 'rails_band/configuration'
5
5
  require 'rails_band/base_event'
6
+ require 'rails_band/deprecation_subscriber'
6
7
  require 'rails_band/railtie'
7
8
 
8
9
  # Rails::Band unsubscribes all default LogSubscribers from Rails Instrumentation API,
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.6.1
4
+ version: 0.7.0
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-04-01 00:00:00.000000000 Z
11
+ date: 2022-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -63,6 +63,7 @@ files:
63
63
  - lib/rails_band/action_mailer/event/process.rb
64
64
  - lib/rails_band/action_mailer/log_subscriber.rb
65
65
  - lib/rails_band/action_view/event/render_collection.rb
66
+ - lib/rails_band/action_view/event/render_layout.rb
66
67
  - lib/rails_band/action_view/event/render_partial.rb
67
68
  - lib/rails_band/action_view/event/render_template.rb
68
69
  - lib/rails_band/action_view/from_views.rb
@@ -104,6 +105,7 @@ files:
104
105
  - lib/rails_band/active_support/log_subscriber.rb
105
106
  - lib/rails_band/base_event.rb
106
107
  - lib/rails_band/configuration.rb
108
+ - lib/rails_band/deprecation_subscriber.rb
107
109
  - lib/rails_band/railtie.rb
108
110
  - lib/rails_band/version.rb
109
111
  homepage: https://github.com/yykamei/rails_band