Skip to content

Commit 9f857ad

Browse files
authored
Support Rails edge version (7.1), add to CI checks (#24)
1 parent bd29d34 commit 9f857ad

File tree

6 files changed

+44
-1
lines changed

6 files changed

+44
-1
lines changed

.github/workflows/main.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,25 @@ jobs:
2727
- truffleruby-23.0.0
2828
- truffleruby-22.1.0
2929
gemfile:
30+
- rails-edge
3031
- rails-7.0
3132
- rails-6.1
3233
- rails-6.0
3334
- rails-5.2
3435
- rails-5.1
3536
- rails-5.0
3637
exclude:
38+
- gemfile: rails-edge
39+
ruby-version: 2.6.6
40+
- gemfile: rails-edge
41+
ruby-version: 2.5.8
42+
- gemfile: rails-edge
43+
ruby-version: jruby-9.4.3.0
44+
- gemfile: rails-edge
45+
ruby-version: jruby-9.2.14.0
46+
- gemfile: rails-edge
47+
ruby-version: truffleruby-23.0.0
48+
3749
- gemfile: rails-7.0
3850
ruby-version: 2.6.6
3951
- gemfile: rails-7.0

gemfiles/rails-edge.gemfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'rails', github: 'rails/rails', branch: 'main'
4+
5+
gem 'logtail'
6+
gem 'logtail-rack'
7+
8+
if RUBY_PLATFORM == "java"
9+
gem 'mime-types', '2.6.2'
10+
end
11+
12+
gemspec :path => '../'

lib/logtail-rails/action_controller/log_subscriber.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module ActionController
77
# @private
88
class LogSubscriber < Integrator
99
def initialize
10+
require "action_controller"
1011
require "action_controller/log_subscriber"
1112
require "logtail-rails/action_controller/log_subscriber/logtail_log_subscriber"
1213
rescue LoadError => e

lib/logtail-rails/action_view/log_subscriber/logtail_log_subscriber.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def render_template(event)
2525
)
2626
end
2727
end
28+
subscribe_log_level :render_template, :info if defined?(subscribe_log_level)
2829

2930
def render_partial(event)
3031
return true if silence?
@@ -66,6 +67,18 @@ def render_collection(event)
6667
end
6768
end
6869

70+
def self.attach_to(*)
71+
super
72+
73+
if ::Rails::VERSION::MAJOR > 7 || ::Rails::VERSION::MAJOR == 7 && ::Rails::VERSION::MINOR >= 1
74+
# Clean extra listeners subscribed in parent's attach_to method
75+
::ActiveSupport::Notifications.notifier.listeners_for("render_template.action_view")
76+
.concat(::ActiveSupport::Notifications.notifier.listeners_for("render_layout.action_view")).flatten
77+
.filter { |listener| listener.delegate.class == ::ActionView::LogSubscriber::Start }
78+
.each { |listener| ActiveSupport::Notifications.unsubscribe(listener) }
79+
end
80+
end
81+
6982
private
7083
def log_rendering_start(*args)
7184
# Consolidates 2 template rendering events into 1. We don't need 2 events for

lib/logtail-rails/active_support_log_subscriber.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ def subscribed?(component, type)
1818
# I don't know why this has to be so complicated, but it is. This code was taken from
1919
# lograge :/
2020
def unsubscribe!(component, type)
21+
if defined?(type.detach_from)
22+
type.detach_from(component)
23+
return
24+
end
25+
2126
subscriber = find(component, type)
2227

2328
if !subscriber

lib/logtail-rails/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Logtail
22
module Integrations
33
module Rails
4-
VERSION = "0.2.3"
4+
VERSION = "0.2.4"
55
end
66
end
77
end

0 commit comments

Comments
 (0)