Skip to content

Commit 9e97777

Browse files
committed
RuboCop Automated Reformatting
1 parent 54f6336 commit 9e97777

File tree

20 files changed

+104
-93
lines changed

20 files changed

+104
-93
lines changed

.rubocop.yml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
AllCops:
2-
TargetRubyVersion: 2.4
32
Exclude:
4-
- '.git/**/*'
5-
- '.github/**/*'
6-
- 'gemfiles/**/*'
3+
- ".git/**/*"
4+
- "docs/**/*"
5+
- "gemfiles/*"
6+
NewCops: enable
7+
TargetRubyVersion: 2.5
78

89
#
910
# RuboCop built-in settings.
@@ -31,7 +32,7 @@ Layout/HashAlignment:
3132
Layout/LineLength:
3233
Max: 128
3334
Exclude:
34-
- '**/test/**/*'
35+
- "**/test/**/*"
3536

3637
# Match existing layout
3738
Layout/SpaceInsideHashLiteralBraces:
@@ -44,17 +45,17 @@ Metrics/AbcSize:
4445
# Support long block lengths for tests
4546
Metrics/BlockLength:
4647
Exclude:
47-
- 'test/**/*'
48-
- '**/*/cli.rb'
49-
ExcludedMethods:
50-
- 'aasm'
51-
- 'included'
48+
- "test/**/*"
49+
- "**/*/cli.rb"
50+
AllowedMethods:
51+
- "aasm"
52+
- "included"
5253

5354
# Soften limits
5455
Metrics/ClassLength:
5556
Max: 250
5657
Exclude:
57-
- 'test/**/*'
58+
- "test/**/*"
5859

5960
# TODO: Soften Limits for phase 1 only
6061
Metrics/CyclomaticComplexity:
@@ -77,15 +78,15 @@ Metrics/PerceivedComplexity:
7778

7879
# Initialization Vector abbreviation
7980
Naming/MethodParameterName:
80-
AllowedNames: ['iv', '_', 'io', 'ap']
81+
AllowedNames: [ "iv", "_", "io", "ap", "id", "_id" ]
8182

8283
# Does not allow Symbols to load
8384
Security/YAMLLoad:
8485
AutoCorrect: false
8586

8687
# Needed for testing DateTime
8788
Style/DateTime:
88-
Exclude: ['test/**/*']
89+
Exclude: [ "test/**/*" ]
8990

9091
# TODO: Soften Limits for phase 1 only
9192
Style/Documentation:

lib/rails_semantic_logger.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,27 @@ module RailsSemanticLogger
66
module ActionController
77
autoload :LogSubscriber, "rails_semantic_logger/action_controller/log_subscriber"
88
end
9+
910
module ActionMailer
1011
autoload :LogSubscriber, "rails_semantic_logger/action_mailer/log_subscriber"
1112
end
13+
1214
module ActionView
1315
autoload :LogSubscriber, "rails_semantic_logger/action_view/log_subscriber"
1416
end
17+
1518
module ActiveJob
1619
autoload :LogSubscriber, "rails_semantic_logger/active_job/log_subscriber"
1720
end
21+
1822
module ActiveRecord
1923
autoload :LogSubscriber, "rails_semantic_logger/active_record/log_subscriber"
2024
end
25+
2126
module Rack
2227
autoload :Logger, "rails_semantic_logger/rack/logger"
2328
end
29+
2430
module DelayedJob
2531
autoload :Plugin, "rails_semantic_logger/delayed_job/plugin"
2632
end
@@ -48,9 +54,11 @@ def self.unattach(subscriber)
4854
end
4955

5056
def self.subscriber_patterns(subscriber)
51-
subscriber.patterns.respond_to?(:keys) ?
52-
subscriber.patterns.keys :
57+
if subscriber.patterns.respond_to?(:keys)
58+
subscriber.patterns.keys
59+
else
5360
subscriber.patterns
61+
end
5462
end
5563

5664
private_class_method :subscriber_patterns, :unattach

lib/rails_semantic_logger/action_controller/log_subscriber.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ def process_action(event)
1414

1515
# Unused, but needed for Devise 401 status code monkey patch to still work.
1616
::ActionController::Base.log_process_action(payload)
17-
17+
1818
params = payload[:params]
1919

20-
if params.kind_of?(Hash) || params.kind_of?(::ActionController::Parameters)
20+
if params.is_a?(Hash) || params.is_a?(::ActionController::Parameters)
2121
# According to PR https://github.com/reidmorrison/rails_semantic_logger/pull/37/files
2222
# params is not always a Hash.
2323
payload[:params] = params.to_unsafe_h unless params.is_a?(Hash)
@@ -79,7 +79,9 @@ def redirect_to(event)
7979
end
8080

8181
def send_data(event)
82-
controller_logger(event).info(message: "Sent data", payload: {file_name: event.payload[:filename]}, duration: event.duration)
82+
controller_logger(event).info(message: "Sent data",
83+
payload: {file_name: event.payload[:filename]},
84+
duration: event.duration)
8385
end
8486

8587
def unpermitted_parameters(event)

lib/rails_semantic_logger/action_mailer/log_subscriber.rb

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ def deliver(event)
99
message_id = event.payload[:message_id]
1010
duration = event.duration.round(1)
1111
if ex
12-
log_with_formatter event: event, log_duration: true, level: :error do |fmt|
12+
log_with_formatter event: event, log_duration: true, level: :error do |_fmt|
1313
{
14-
message: "Error delivering mail #{message_id} (#{duration}ms)",
14+
message: "Error delivering mail #{message_id} (#{duration}ms)",
1515
exception: ex
1616
}
1717
end
1818
else
19-
message = begin
19+
message =
2020
if event.payload[:perform_deliveries]
2121
"Delivered mail #{message_id} (#{duration}ms)"
2222
else
2323
"Skipped delivery of mail #{message_id} as `perform_deliveries` is false"
2424
end
25-
end
26-
log_with_formatter event: event, log_duration: true do |fmt|
27-
{ message: message }
25+
26+
log_with_formatter event: event, log_duration: true do |_fmt|
27+
{message: message}
2828
end
2929
end
3030
end
@@ -34,8 +34,8 @@ def process(event)
3434
mailer = event.payload[:mailer]
3535
action = event.payload[:action]
3636
duration = event.duration.round(1)
37-
log_with_formatter event: event do |fmt|
38-
{ message: "#{mailer}##{action}: processed outbound mail in #{duration}ms" }
37+
log_with_formatter event: event do |_fmt|
38+
{message: "#{mailer}##{action}: processed outbound mail in #{duration}ms"}
3939
end
4040
end
4141

@@ -74,8 +74,6 @@ def date
7474
event.payload[:date].to_time.utc
7575
elsif event.payload[:date].is_a?(String)
7676
Time.parse(date).utc
77-
else
78-
nil
7977
end
8078
end
8179

@@ -94,8 +92,8 @@ def action
9492
def formatted_args
9593
if defined?(mailer.constantize.log_arguments?) && !mailer.constantize.log_arguments?
9694
""
97-
else
98-
JSON.pretty_generate(event.payload[:args].map { |arg| format(arg) }) if event.payload[:args].present?
95+
elsif event.payload[:args].present?
96+
JSON.pretty_generate(event.payload[:args].map { |arg| format(arg) })
9997
end
10098
end
10199

lib/rails_semantic_logger/action_view/log_subscriber.rb

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def initialize
1919
def render_template(event)
2020
return unless should_log?
2121

22-
payload = {
22+
payload = {
2323
template: from_rails_root(event.payload[:identifier])
2424
}
2525
payload[:within] = from_rails_root(event.payload[:layout]) if event.payload[:layout]
@@ -36,7 +36,7 @@ def render_template(event)
3636
def render_partial(event)
3737
return unless should_log?
3838

39-
payload = {
39+
payload = {
4040
partial: from_rails_root(event.payload[:identifier])
4141
}
4242
payload[:within] = from_rails_root(event.payload[:layout]) if event.payload[:layout]
@@ -56,7 +56,7 @@ def render_collection(event)
5656

5757
identifier = event.payload[:identifier] || "templates"
5858

59-
payload = {
59+
payload = {
6060
template: from_rails_root(identifier),
6161
count: event.payload[:count]
6262
}
@@ -72,9 +72,9 @@ def render_collection(event)
7272
end
7373

7474
def start(name, id, payload)
75-
if (name == "render_template.action_view" || name == "render_layout.action_view") && should_log?
75+
if ["render_template.action_view", "render_layout.action_view"].include?(name) && should_log?
7676
qualifier = " layout" if name == "render_layout.action_view"
77-
payload = { template: from_rails_root(payload[:identifier]) }
77+
payload = {template: from_rails_root(payload[:identifier])}
7878
payload[:within] = from_rails_root(payload[:layout]) if payload[:layout]
7979

8080
logger.send(self.class.rendered_log_level, message: "Rendering#{qualifier}", payload: payload)
@@ -84,18 +84,19 @@ def start(name, id, payload)
8484
end
8585

8686
if (Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR >= 1) || Rails::VERSION::MAJOR > 7
87-
class Start # :nodoc:
88-
def start(name, id, payload)
87+
class Start
88+
def start(name, _id, payload)
8989
return unless %w[render_template.action_view render_layout.action_view].include?(name)
9090

9191
qualifier = " layout" if name == "render_layout.action_view"
92-
payload = { template: from_rails_root(payload[:identifier]) }
92+
payload = {template: from_rails_root(payload[:identifier])}
9393
payload[:within] = from_rails_root(payload[:layout]) if payload[:layout]
9494

9595
logger.debug(message: "Rendering#{qualifier}", payload: payload)
9696
end
9797

98-
def finish(name, id, payload) end
98+
def finish(name, id, payload)
99+
end
99100

100101
private
101102

@@ -105,7 +106,7 @@ def from_rails_root(string)
105106
string
106107
end
107108

108-
def rails_root # :doc:
109+
def rails_root
109110
@root ||= "#{Rails.root}/"
110111
end
111112

@@ -117,8 +118,10 @@ def logger
117118
def self.attach_to(*)
118119
ActiveSupport::Notifications.unsubscribe("render_template.action_view")
119120
ActiveSupport::Notifications.unsubscribe("render_layout.action_view")
120-
ActiveSupport::Notifications.subscribe("render_template.action_view", RailsSemanticLogger::ActionView::LogSubscriber::Start.new)
121-
ActiveSupport::Notifications.subscribe("render_layout.action_view", RailsSemanticLogger::ActionView::LogSubscriber::Start.new)
121+
ActiveSupport::Notifications.subscribe("render_template.action_view",
122+
RailsSemanticLogger::ActionView::LogSubscriber::Start.new)
123+
ActiveSupport::Notifications.subscribe("render_layout.action_view",
124+
RailsSemanticLogger::ActionView::LogSubscriber::Start.new)
122125

123126
super
124127
end

lib/rails_semantic_logger/active_job/log_subscriber.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ def enqueue(event)
99
if ex
1010
log_with_formatter level: :error, event: event do |fmt|
1111
{
12-
message: "Failed enqueuing #{fmt.job_info} (#{ex.class} (#{ex.message})",
12+
message: "Failed enqueuing #{fmt.job_info} (#{ex.class} (#{ex.message})",
1313
exception: ex
1414
}
1515
end
1616
elsif event.payload[:aborted]
1717
log_with_formatter level: :info, event: event do |fmt|
18-
{ message: "Failed enqueuing #{fmt.job_info}, a before_enqueue callback halted the enqueuing execution." }
18+
{message: "Failed enqueuing #{fmt.job_info}, a before_enqueue callback halted the enqueuing execution."}
1919
end
2020
else
2121
log_with_formatter event: event do |fmt|
22-
{ message: "Enqueued #{fmt.job_info}" }
22+
{message: "Enqueued #{fmt.job_info}"}
2323
end
2424
end
2525
end
@@ -30,13 +30,13 @@ def enqueue_at(event)
3030
if ex
3131
log_with_formatter level: :error, event: event do |fmt|
3232
{
33-
message: "Failed enqueuing #{fmt.job_info} (#{ex.class} (#{ex.message})",
33+
message: "Failed enqueuing #{fmt.job_info} (#{ex.class} (#{ex.message})",
3434
exception: ex
3535
}
3636
end
3737
elsif event.payload[:aborted]
3838
log_with_formatter level: :info, event: event do |fmt|
39-
{ message: "Failed enqueuing #{fmt.job_info}, a before_enqueue callback halted the enqueuing execution." }
39+
{message: "Failed enqueuing #{fmt.job_info}, a before_enqueue callback halted the enqueuing execution."}
4040
end
4141
else
4242
log_with_formatter event: event do |fmt|
@@ -56,7 +56,7 @@ def perform(event)
5656
if ex
5757
log_with_formatter event: event, log_duration: true, level: :error do |fmt|
5858
{
59-
message: "Error performing #{fmt.job_info} in #{event.duration.round(2)}ms",
59+
message: "Error performing #{fmt.job_info} in #{event.duration.round(2)}ms",
6060
exception: ex
6161
}
6262
end

lib/rails_semantic_logger/active_record/log_subscriber.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,7 @@ def render_bind_v5_0_3(attr, value)
169169
def render_bind_v6_1(attr, value)
170170
case attr
171171
when ActiveModel::Attribute
172-
if attr.type.binary? && attr.value
173-
value = "<#{attr.value_for_database.to_s.bytesize} bytes of binary data>"
174-
end
172+
value = "<#{attr.value_for_database.to_s.bytesize} bytes of binary data>" if attr.type.binary? && attr.value
175173
when Array
176174
attr = attr.first
177175
else

lib/rails_semantic_logger/engine.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Engine < ::Rails::Engine
7777
logger = SemanticLogger[Rails]
7878
logger.warn(
7979
"Rails Error: Unable to access log file. Please ensure that #{path} exists and is chmod 0666. " \
80-
"The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.",
80+
"The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.",
8181
e
8282
)
8383
logger
@@ -111,14 +111,14 @@ class Engine < ::Rails::Engine
111111
if defined?(Sidekiq)
112112
if Sidekiq.respond_to?(:logger=)
113113
Sidekiq.logger = SemanticLogger[Sidekiq]
114-
elsif Sidekiq::VERSION[0..1] == '7.'
114+
elsif Sidekiq::VERSION[0..1] == "7."
115115
method = Sidekiq.server? ? :configure_server : :configure_client
116116
Sidekiq.public_send(method) { |cfg| cfg.logger = SemanticLogger[Sidekiq] }
117117
end
118118
end
119119

120120
# Replace the Sidetiq logger
121-
Sidetiq.logger = SemanticLogger[Sidetiq] if defined?(Sidetiq) && Sidetiq.respond_to?(:logger=)
121+
Sidetiq.logger = SemanticLogger[Sidetiq] if defined?(Sidetiq) && Sidetiq.respond_to?(:logger=)
122122

123123
# Replace the DelayedJob logger
124124
if defined?(Delayed::Worker)
@@ -143,7 +143,9 @@ class Engine < ::Rails::Engine
143143
# Rails Patches
144144
require("rails_semantic_logger/extensions/action_cable/tagged_logger_proxy") if defined?(::ActionCable)
145145
require("rails_semantic_logger/extensions/action_controller/live") if defined?(::ActionController::Live)
146-
require("rails_semantic_logger/extensions/action_dispatch/debug_exceptions") if defined?(::ActionDispatch::DebugExceptions)
146+
if defined?(::ActionDispatch::DebugExceptions)
147+
require("rails_semantic_logger/extensions/action_dispatch/debug_exceptions")
148+
end
147149
if defined?(::ActionView::StreamingTemplateRenderer::Body)
148150
require("rails_semantic_logger/extensions/action_view/streaming_template_renderer")
149151
end

lib/rails_semantic_logger/extensions/active_support/log_subscriber.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if ActiveSupport::VERSION::STRING == '7.1.1'
1+
if ActiveSupport::VERSION::STRING == "7.1.1"
22
require "active_support/log_subscriber"
33

44
module ActiveSupport

lib/rails_semantic_logger/extensions/active_support/logger.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ class << self
99
# Prevent broadcasting since SemanticLogger already supports multiple loggers
1010
if method_defined?(:broadcast)
1111
undef :broadcast
12-
def broadcast(logger)
12+
def broadcast(_logger)
1313
Module.new
1414
end
1515
end
1616
end
1717

1818
# Prevent Console from trying to merge loggers
19-
def self.logger_outputs_to?(*args)
19+
def self.logger_outputs_to?(*_args)
2020
true
2121
end
2222

23-
def self.new(*args, **kwargs)
23+
def self.new(*_args, **_kwargs)
2424
SemanticLogger[self]
2525
end
2626
end

0 commit comments

Comments
 (0)