Skip to content

Commit e246354

Browse files
refactor: Use Block Argument Forwarding (#1389)
* refactor: Use Block Argument Forwading > This cop identifies places where do_something(&block) can be replaced by do_something(&) https://docs.rubocop.org/rubocop/cops_style.html#styleargumentsforwarding https://docs.rubocop.org/rubocop/cops_naming.html#namingblockforwarding * squash: update que * squash: action mailer * squash: active record * squash: active_storage * squash: aws-sdk * squash: concurrent-ruby * squash: delayed job * squash: http_client * squash: graphql * squash: koala * squash: net_http * squash: restclient * squash: rspec --------- Co-authored-by: Kayla Reopelle <[email protected]>
1 parent 6c7b608 commit e246354

File tree

22 files changed

+58
-64
lines changed

22 files changed

+58
-64
lines changed

.rubocop.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ Metrics/PerceivedComplexity:
3838
Naming/FileName:
3939
Exclude:
4040
- '**/opentelemetry-*'
41-
### TODO: Enable this is a separate PR
42-
Naming/BlockForwarding:
43-
Enabled: false
44-
Style/ArgumentsForwarding:
45-
Enabled: false
46-
#######################
4741
Style/Documentation:
4842
Exclude:
4943
- "**/test/**/*"

instrumentation/action_mailer/test/opentelemetry/instrumentation/action_mailer/subscription_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
end
117117
end
118118

119-
def with_configuration(values, &block)
119+
def with_configuration(values, &)
120120
original_config = instrumentation.instance_variable_get(:@config)
121121
modified_config = original_config.merge(values)
122122
instrumentation.instance_variable_set(:@config, modified_config)
@@ -126,14 +126,14 @@ def with_configuration(values, &block)
126126
instrumentation.instance_variable_set(:@config, original_config)
127127
end
128128

129-
def subscribing_to_deliver(&block)
129+
def subscribing_to_deliver(&)
130130
subscription = OpenTelemetry::Instrumentation::ActionMailer::Railtie.subscribe_to_deliver
131131
yield
132132
ensure
133133
ActiveSupport::Notifications.unsubscribe(subscription)
134134
end
135135

136-
def subscribing_to_process(&block)
136+
def subscribing_to_process(&)
137137
subscription = OpenTelemetry::Instrumentation::ActionMailer::Railtie.subscribe_to_process
138138
yield
139139
ensure

instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/patches/persistence.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,91 +29,91 @@ def destroy!
2929
end
3030
end
3131

32-
def becomes(klass)
32+
def becomes(...)
3333
tracer.in_span("#{self.class}#becomes") do
3434
super
3535
end
3636
end
3737

38-
def becomes!(klass)
38+
def becomes!(...)
3939
tracer.in_span("#{self.class}#becomes!") do
4040
super
4141
end
4242
end
4343

44-
def update_attribute(name, value)
44+
def update_attribute(...)
4545
tracer.in_span("#{self.class}#update_attribute") do
4646
super
4747
end
4848
end
4949

50-
def update(attributes)
50+
def update(...)
5151
tracer.in_span("#{self.class}#update") do
5252
super
5353
end
5454
end
5555

56-
def update!(attributes)
56+
def update!(...)
5757
tracer.in_span("#{self.class}#update!") do
5858
super
5959
end
6060
end
6161

62-
def update_column(name, value)
62+
def update_column(...)
6363
tracer.in_span("#{self.class}#update_column") do
6464
super
6565
end
6666
end
6767

68-
def update_columns(attributes)
68+
def update_columns(...)
6969
tracer.in_span("#{self.class}#update_columns") do
7070
super
7171
end
7272
end
7373

74-
def increment(attribute, by = 1)
74+
def increment(...)
7575
tracer.in_span("#{self.class}#increment") do
7676
super
7777
end
7878
end
7979

80-
def increment!(attribute, by = 1, touch: nil)
80+
def increment!(...)
8181
tracer.in_span("#{self.class}#increment!") do
8282
super
8383
end
8484
end
8585

86-
def decrement(attribute, by = 1)
86+
def decrement(...)
8787
tracer.in_span("#{self.class}#decrement") do
8888
super
8989
end
9090
end
9191

92-
def decrement!(attribute, by = 1, touch: nil)
92+
def decrement!(...)
9393
tracer.in_span("#{self.class}#decrement!") do
9494
super
9595
end
9696
end
9797

98-
def toggle(attribute)
98+
def toggle(...)
9999
tracer.in_span("#{self.class}#toggle") do
100100
super
101101
end
102102
end
103103

104-
def toggle!(attribute)
104+
def toggle!(...)
105105
tracer.in_span("#{self.class}#toggle!") do
106106
super
107107
end
108108
end
109109

110-
def reload(options = nil)
110+
def reload(...)
111111
tracer.in_span("#{self.class}#reload") do
112112
super
113113
end
114114
end
115115

116-
def touch(*names, time: nil)
116+
def touch(...)
117117
tracer.in_span("#{self.class}#touch") do
118118
super
119119
end

instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/patches/persistence_class_methods.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,31 @@ class << base
1818

1919
# Contains ActiveRecord::Persistence::ClassMethods to be patched
2020
module ClassMethods
21-
def create(attributes = nil, &block)
21+
def create(...)
2222
tracer.in_span("#{self}.create") do
2323
super
2424
end
2525
end
2626

27-
def create!(attributes = nil, &block)
27+
def create!(...)
2828
tracer.in_span("#{self}.create!") do
2929
super
3030
end
3131
end
3232

33-
def update(id = :all, attributes) # rubocop:disable Style/OptionalArguments
33+
def update(...)
3434
tracer.in_span("#{self}.update") do
3535
super
3636
end
3737
end
3838

39-
def destroy(id)
39+
def destroy(...)
4040
tracer.in_span("#{self}.destroy") do
4141
super
4242
end
4343
end
4444

45-
def delete(id_or_array)
45+
def delete(...)
4646
tracer.in_span("#{self}.delete") do
4747
super
4848
end

instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/patches/persistence_insert_class_methods.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,37 @@ class << base
1818

1919
# Contains ActiveRecord::Persistence::ClassMethods to be patched
2020
module ClassMethods
21-
ruby2_keywords def insert(*args)
21+
def insert(...)
2222
tracer.in_span("#{self}.insert") do
2323
super
2424
end
2525
end
2626

27-
ruby2_keywords def insert_all(*args)
27+
def insert_all(...)
2828
tracer.in_span("#{self}.insert_all") do
2929
super
3030
end
3131
end
3232

33-
ruby2_keywords def insert!(*args)
33+
def insert!(...)
3434
tracer.in_span("#{self}.insert!") do
3535
super
3636
end
3737
end
3838

39-
ruby2_keywords def insert_all!(*args)
39+
def insert_all!(...)
4040
tracer.in_span("#{self}.insert_all!") do
4141
super
4242
end
4343
end
4444

45-
ruby2_keywords def upsert(*args)
45+
def upsert(...)
4646
tracer.in_span("#{self}.upsert") do
4747
super
4848
end
4949
end
5050

51-
ruby2_keywords def upsert_all(*args)
51+
def upsert_all(...)
5252
tracer.in_span("#{self}.upsert_all") do
5353
super
5454
end

instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/patches/relation_persistence.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ module ActiveRecord
1010
module Patches
1111
# Module to prepend to ActiveRecord::Relation for instrumentation
1212
module RelationPersistence
13-
def update_all(*)
13+
def update_all(...)
1414
tracer.in_span("#{model.name}.update_all") do
1515
super
1616
end
1717
end
1818

19-
def delete_all(*)
19+
def delete_all(...)
2020
tracer.in_span("#{model.name}.delete_all") do
2121
super
2222
end

instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/patches/transactions_class_methods.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class << base
1818

1919
# Contains ActiveRecord::Transactions::ClassMethods to be patched
2020
module ClassMethods
21-
def transaction(**options, &block)
21+
def transaction(...)
2222
tracer.in_span('ActiveRecord.transaction', attributes: { 'code.namespace' => name }) do
2323
super
2424
end

instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/patches/validations.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ module Patches
1414
# https://github.com/rails/rails/blob/v5.2.4.5/activerecord/lib/active_record/validations.rb#L42-L53
1515
# Contains the ActiveRecord::Validations methods to be patched
1616
module Validations
17-
def save(**options)
17+
def save(...)
1818
tracer.in_span("#{self.class}#save") do
1919
super
2020
end
2121
end
2222

23-
def save!(**options)
23+
def save!(...)
2424
tracer.in_span("#{self.class}#save!") do
2525
super
2626
end

instrumentation/active_storage/test/opentelemetry/instrumentation/active_storage/subscription_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@
341341
# NOTE: The test for service_update_metadata.active_storage is skipped because this event is only for GCS service.
342342
# https://github.com/rails/rails/blob/fa9cf269191c5077de1abdd1e3f934fbeaf2a5d0/guides/source/active_support_instrumentation.md?plain=1#L928
343343

344-
def with_configuration(values, &block)
344+
def with_configuration(values, &)
345345
original_config = instrumentation.instance_variable_get(:@config)
346346
modified_config = original_config.merge(values)
347347
instrumentation.instance_variable_set(:@config, modified_config)
@@ -351,7 +351,7 @@ def with_configuration(values, &block)
351351
instrumentation.instance_variable_set(:@config, original_config)
352352
end
353353

354-
def with_subscription(&block)
354+
def with_subscription(&)
355355
OpenTelemetry::Instrumentation::ActiveStorage::Railtie.subscribe
356356
yield
357357
ensure

instrumentation/active_storage/test/test_helpers/test_previewer.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def preview(**options)
2222

2323
private
2424

25-
def draw_sample_image(file, &block)
26-
draw 'echo', '"test previewer called"', &block
25+
def draw_sample_image(file, &)
26+
draw('echo', '"test previewer called"', &)
2727
end
2828
end

0 commit comments

Comments
 (0)