Skip to content

Commit

Permalink
Fix rubocop 1.23.0 violations
Browse files Browse the repository at this point in the history
These fixes were automatically made with:

    rubocop --auto-correct-all
  • Loading branch information
ivy authored and Ivy Evans committed Nov 17, 2021
1 parent cd803be commit f8269a0
Show file tree
Hide file tree
Showing 46 changed files with 147 additions and 67 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in lograge.gemspec
Expand Down
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'

require 'rspec/core/rake_task'
Expand All @@ -7,6 +9,6 @@ require 'rubocop/rake_task'
RuboCop::RakeTask.new

desc 'Run specs, rubocop and reek'
task ci: %w(spec rubocop)
task ci: %w[spec rubocop]

task default: :ci
2 changes: 2 additions & 0 deletions gemfiles/actionpack4.0.gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in lograge.gemspec
Expand Down
4 changes: 3 additions & 1 deletion gemfiles/actionpack5.0.gemfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in lograge.gemspec
gemspec path: '..'

group :test do
gem 'activerecord', '~> 5.0.0'
gem 'actionpack', '~> 5.0.0'
gem 'activerecord', '~> 5.0.0'

# logstash does not release any gems on rubygems, but they have two gemspecs within their repo.
# Using the tag is an attempt of having a stable version to test against where we can ensure that
Expand Down
4 changes: 3 additions & 1 deletion gemfiles/actionpack5.1.gemfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in lograge.gemspec
gemspec path: '..'

group :test do
gem 'activerecord', '~> 5.1.0'
gem 'actionpack', '~> 5.1.0'
gem 'activerecord', '~> 5.1.0'

# logstash does not release any gems on rubygems, but they have two gemspecs within their repo.
# Using the tag is an attempt of having a stable version to test against where we can ensure that
Expand Down
4 changes: 3 additions & 1 deletion gemfiles/actionpack5.2.gemfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in lograge.gemspec
gemspec path: '..'

group :test do
gem 'activerecord', '~> 5.2.0'
gem 'actionpack', '~> 5.2.0'
gem 'activerecord', '~> 5.2.0'

# logstash does not release any gems on rubygems, but they have two gemspecs within their repo.
# Using the tag is an attempt of having a stable version to test against where we can ensure that
Expand Down
10 changes: 5 additions & 5 deletions lib/lograge.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'lograge/version'
require 'lograge/formatters/helpers/method_and_path'
require 'lograge/formatters/cee'
Expand All @@ -17,7 +19,7 @@
require 'active_support/core_ext/module/attribute_accessors'
require 'active_support/core_ext/string/inflections'

# rubocop:disable ModuleLength
# rubocop:disable Metrics/ModuleLength
module Lograge
module_function

Expand Down Expand Up @@ -117,9 +119,7 @@ def unsubscribe(component, subscriber)
events = subscriber.public_methods(false).reject { |method| method.to_s == 'call' }
events.each do |event|
ActiveSupport::Notifications.notifier.listeners_for("#{event}.#{component}").each do |listener|
if listener.instance_variable_get('@delegate') == subscriber
ActiveSupport::Notifications.unsubscribe listener
end
ActiveSupport::Notifications.unsubscribe listener if listener.instance_variable_get('@delegate') == subscriber
end
end
end
Expand Down Expand Up @@ -203,7 +203,7 @@ def keep_original_rails_log
end

def rack_cache_hashlike?(app)
app.config.action_dispatch.rack_cache && app.config.action_dispatch.rack_cache.respond_to?(:[]=)
app.config.action_dispatch.rack_cache&.respond_to?(:[]=)
end
private_class_method :rack_cache_hashlike?

Expand Down
2 changes: 2 additions & 0 deletions lib/lograge/formatters/cee.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Lograge
module Formatters
class Cee
Expand Down
4 changes: 3 additions & 1 deletion lib/lograge/formatters/graylog2.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Lograge
module Formatters
class Graylog2
Expand All @@ -12,7 +14,7 @@ def call(data)
}

# Add underscore to every key to follow GELF additional field syntax.
data_clone.keys.each do |key|
data_clone.each_key do |key|
data_clone[underscore_prefix(key)] = data_clone[key]
data_clone.delete(key)
end
Expand Down
2 changes: 2 additions & 0 deletions lib/lograge/formatters/helpers/method_and_path.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Lograge
module Formatters
module Helpers
Expand Down
2 changes: 2 additions & 0 deletions lib/lograge/formatters/json.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'json'
module Lograge
module Formatters
Expand Down
2 changes: 2 additions & 0 deletions lib/lograge/formatters/key_value.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Lograge
module Formatters
class KeyValue
Expand Down
30 changes: 16 additions & 14 deletions lib/lograge/formatters/l2met.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
# frozen_string_literal: true

require 'lograge/formatters/key_value'

module Lograge
module Formatters
class L2met < KeyValue
L2MET_FIELDS = [
:method,
:path,
:format,
:source,
:status,
:error,
:duration,
:view,
:db,
:location
L2MET_FIELDS = %i[
method
path
format
source
status
error
duration
view
db
location
].freeze

UNWANTED_FIELDS = [
:controller,
:action
UNWANTED_FIELDS = %i[
controller
action
].freeze

def call(data)
Expand Down
2 changes: 2 additions & 0 deletions lib/lograge/formatters/lines.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Lograge
module Formatters
class Lines
Expand Down
2 changes: 2 additions & 0 deletions lib/lograge/formatters/logstash.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Lograge
module Formatters
class Logstash
Expand Down
2 changes: 2 additions & 0 deletions lib/lograge/formatters/ltsv.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Lograge
module Formatters
class LTSV
Expand Down
2 changes: 2 additions & 0 deletions lib/lograge/formatters/raw.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Lograge
module Formatters
class Raw
Expand Down
4 changes: 3 additions & 1 deletion lib/lograge/log_subscribers/action_cable.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true

module Lograge
module LogSubscribers
class ActionCable < Base
%i(perform_action subscribe unsubscribe connect disconnect).each do |method_name|
%i[perform_action subscribe unsubscribe connect disconnect].each do |method_name|
define_method(method_name) do |event|
process_main_event(event)
end
Expand Down
2 changes: 2 additions & 0 deletions lib/lograge/log_subscribers/action_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Lograge
module LogSubscribers
class ActionController < Base
Expand Down
6 changes: 4 additions & 2 deletions lib/lograge/log_subscribers/base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'json'
require 'action_pack'
require 'active_support/core_ext/class/attribute'
Expand Down Expand Up @@ -32,8 +34,8 @@ def extract_request(event, payload)
data.merge!(custom_options(event))
end

%i(initial_data extract_status extract_runtimes
extract_location extract_unpermitted_params).each do |method_name|
%i[initial_data extract_status extract_runtimes
extract_location extract_unpermitted_params].each do |method_name|
define_method(method_name) { |*_arg| {} }
end

Expand Down
2 changes: 2 additions & 0 deletions lib/lograge/ordered_options.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'active_support/ordered_options'

module Lograge
Expand Down
2 changes: 2 additions & 0 deletions lib/lograge/rails_ext/action_cable/channel/base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ActionCable
module Channel
class Base
Expand Down
24 changes: 11 additions & 13 deletions lib/lograge/rails_ext/action_cable/connection/base.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
# frozen_string_literal: true

module ActionCable
module Connection
class Base
# rubocop:disable Metrics/MethodLength
def handle_open
ActiveSupport::Notifications.instrument('connect.action_cable', notification_payload('connect')) do
begin
@protocol = websocket.protocol
connect if respond_to?(:connect)
subscribe_to_internal_channel
send_welcome_message

message_buffer.process!
server.add_connection(self)
rescue ActionCable::Connection::Authorization::UnauthorizedError
respond_to_invalid_request
end
@protocol = websocket.protocol
connect if respond_to?(:connect)
subscribe_to_internal_channel
send_welcome_message

message_buffer.process!
server.add_connection(self)
rescue ActionCable::Connection::Authorization::UnauthorizedError
respond_to_invalid_request
end
end
# rubocop:enable Metrics/MethodLength

def handle_close
ActiveSupport::Notifications.instrument('disconnect.action_cable', notification_payload('disconnect')) do
Expand Down
2 changes: 2 additions & 0 deletions lib/lograge/rails_ext/action_cable/server/base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ActionCable
module Server
class Base
Expand Down
5 changes: 3 additions & 2 deletions lib/lograge/rails_ext/rack/logger.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'active_support/concern'
require 'rails/rack/logger'

Expand All @@ -18,8 +20,7 @@ def call_app(*args)
end

# Overwrites Rails 3.0/3.1 code that logs new requests
def before_dispatch(_env)
end
def before_dispatch(_env); end
end
end
end
2 changes: 2 additions & 0 deletions lib/lograge/railtie.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rails/railtie'
require 'action_view/log_subscriber'
require 'action_controller/log_subscriber'
Expand Down
8 changes: 3 additions & 5 deletions lib/lograge/silent_logger.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# frozen_string_literal: true

require 'delegate'

module Lograge
class SilentLogger < SimpleDelegator
def initialize(logger)
super
end

%i(debug info warn error fatal unknown).each do |method_name|
%i[debug info warn error fatal unknown].each do |method_name|
define_method(method_name) { |*_args| }
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/lograge/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Lograge
VERSION = '0.11.2'.freeze
VERSION = '0.11.2'
end
4 changes: 3 additions & 1 deletion lograge.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require './lib/lograge/version'

Gem::Specification.new do |s|
Expand All @@ -15,8 +17,8 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rspec', '~> 3.1'
s.add_development_dependency 'rubocop', '~> 1.23'

s.add_runtime_dependency 'activesupport', '>= 4'
s.add_runtime_dependency 'actionpack', '>= 4'
s.add_runtime_dependency 'activesupport', '>= 4'
s.add_runtime_dependency 'railties', '>= 4'
s.add_runtime_dependency 'request_store', '~> 1.0'
end
2 changes: 2 additions & 0 deletions spec/formatters/cee_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe Lograge::Formatters::Cee do
it 'prepends the output with @cee' do
expect(subject.call({})).to match(/^@cee/)
Expand Down
2 changes: 2 additions & 0 deletions spec/formatters/graylog2_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe Lograge::Formatters::Graylog2 do
let(:payload) do
{
Expand Down
2 changes: 2 additions & 0 deletions spec/formatters/helpers/method_and_path_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe Lograge::Formatters::Helpers::MethodAndPath do
describe '#method_and_path_string' do
let(:instance) do
Expand Down
2 changes: 2 additions & 0 deletions spec/formatters/json_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe Lograge::Formatters::Json do
let(:deserialized_output) { JSON.parse(subject.call(custom: 'data')) }

Expand Down
2 changes: 2 additions & 0 deletions spec/formatters/key_value_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe Lograge::Formatters::KeyValue do
let(:payload) do
{
Expand Down
2 changes: 2 additions & 0 deletions spec/formatters/l2met_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe Lograge::Formatters::L2met do
let(:payload) do
{
Expand Down
2 changes: 2 additions & 0 deletions spec/formatters/lines_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe Lograge::Formatters::Lines do
it 'can serialize custom data' do
expect(subject.call(custom: 'data')).to eq('custom=data')
Expand Down
Loading

0 comments on commit f8269a0

Please sign in to comment.