Skip to content

Commit 5edc9ed

Browse files
committed
Use anonymous variable for blocks where possible
1 parent a9e5c36 commit 5edc9ed

File tree

8 files changed

+52
-52
lines changed

8 files changed

+52
-52
lines changed

lib/rom/sql/dsl.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ def initialize(schema)
2828
end
2929

3030
# @api private
31-
def call(&block)
31+
def call(&)
3232
arg, kwargs = select_relations(block.parameters)
3333

3434
if kwargs.nil?
35-
result = instance_exec(arg, &block)
35+
result = instance_exec(arg, &)
3636
else
37-
result = instance_exec(**kwargs, &block)
37+
result = instance_exec(**kwargs, &)
3838
end
3939

4040
if result.is_a?(::Array)

lib/rom/sql/function.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ def case(mapping)
221221
# @return [SQL::Function]
222222
#
223223
# @api public
224-
def filter(condition = Undefined, &block)
225-
if block
226-
conditions = schema.restriction(&block)
224+
def filter(condition = Undefined, &)
225+
if block_given?
226+
conditions = schema.restriction(&)
227227
conditions &= condition unless condition.equal?(Undefined)
228228
else
229229
conditions = condition
@@ -246,9 +246,9 @@ def filter(condition = Undefined, &block)
246246
# @return [SQL::Function]
247247
#
248248
# @api public
249-
def within_group(*args, &block)
250-
if block
251-
group = args + ::ROM::SQL::OrderDSL.new(schema).(&block)
249+
def within_group(*args, &)
250+
if block_given?
251+
group = args + ::ROM::SQL::OrderDSL.new(schema).(&)
252252
else
253253
group = args
254254
end

lib/rom/sql/migration.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ class << self
5454
# @param [Symbol] gateway The gateway name, :default by default
5555
#
5656
# @api public
57-
def migration(*args, &block)
57+
def migration(*args, &)
5858
if args.any?
5959
container, gateway, * = args
60-
with_gateway(container.gateways[gateway || :default]) { migration(&block) }
60+
with_gateway(container.gateways[gateway || :default]) { migration(&) }
6161
else
62-
current_gateway.migration(&block)
62+
current_gateway.migration(&)
6363
end
6464
end
6565

lib/rom/sql/migration/recorder.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ module Migration
77
class Recorder
88
attr_reader :operations
99

10-
def initialize(&block)
10+
def initialize(&)
1111
@operations = []
1212

13-
instance_exec(&block) if block
13+
instance_exec(&) if block_given?
1414
end
1515

1616
private
@@ -19,8 +19,8 @@ def respond_to_missing?(_m, _include_private = false)
1919
true
2020
end
2121

22-
def method_missing(m, *args, &block)
23-
nested = block ? Recorder.new(&block).operations : EMPTY_ARRAY
22+
def method_missing(m, *args, &)
23+
nested = block_given? ? Recorder.new(&).operations : EMPTY_ARRAY
2424
@operations << [m, args, nested]
2525
end
2626
end

lib/rom/sql/relation/reading.rb

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,9 @@ def avg(*args)
361361
# @return [Relation]
362362
#
363363
# @api public
364-
def where(*args, &block)
365-
if block
366-
where(*args).where(schema.canonical.restriction(&block))
364+
def where(*args, &)
365+
if block_given?
366+
where(*args).where(schema.canonical.restriction(&))
367367
elsif args.size == 1 && args[0].is_a?(Hash)
368368
new(dataset.where(coerce_conditions(args[0])))
369369
elsif !args.empty?
@@ -420,9 +420,9 @@ def exclude(...)
420420
# @return [Relation]
421421
#
422422
# @api public
423-
def having(*args, &block)
424-
if block
425-
new(dataset.having(*args, *schema.canonical.restriction(&block)))
423+
def having(*args, &)
424+
if block_given?
425+
new(dataset.having(*args, *schema.canonical.restriction(&)))
426426
else
427427
new(dataset.__send__(__method__, *args))
428428
end
@@ -475,11 +475,11 @@ def invert
475475
# @return [Relation]
476476
#
477477
# @api public
478-
def order(*args, &block)
479-
if block
480-
new(dataset.order(*args, *schema.canonical.order(&block)))
478+
def order(*args, &)
479+
if block_given?
480+
new(dataset.order(*args, *schema.canonical.order(&)))
481481
else
482-
new(dataset.__send__(__method__, *args, &block))
482+
new(dataset.__send__(__method__, *args, &))
483483
end
484484
end
485485

@@ -724,12 +724,12 @@ def right_join(...)
724724
# @return [Relation]
725725
#
726726
# @api public
727-
def group(*args, &block)
728-
if block
727+
def group(*args, &)
728+
if block_given?
729729
if args.size.positive?
730-
group(*args).group_append(&block)
730+
group(*args).group_append(&)
731731
else
732-
new(dataset.__send__(__method__, *schema.canonical.group(&block)))
732+
new(dataset.__send__(__method__, *schema.canonical.group(&)))
733733
end
734734
else
735735
new(dataset.__send__(__method__, *schema.canonical.project(*args)))
@@ -763,12 +763,12 @@ def group(*args, &block)
763763
# @return [Relation]
764764
#
765765
# @api public
766-
def group_append(*args, &block)
767-
if block
766+
def group_append(*args, &)
767+
if block_given?
768768
if args.size.positive?
769-
group_append(*args).group_append(&block)
769+
group_append(*args).group_append(&)
770770
else
771-
new(dataset.group_append(*schema.canonical.group(&block)))
771+
new(dataset.group_append(*schema.canonical.group(&)))
772772
end
773773
else
774774
new(dataset.group_append(*args))
@@ -910,12 +910,12 @@ def read(sql)
910910
# @yieldparam relation [Array]
911911
#
912912
# @api public
913-
def lock(**options, &block)
913+
def lock(**options, &)
914914
clause = lock_clause(**options)
915915

916-
if block
916+
if block_given?
917917
transaction do
918-
block.call(dataset.lock_style(clause).to_a)
918+
yield(dataset.lock_style(clause).to_a)
919919
end
920920
else
921921
new(dataset.lock_style(clause))
@@ -1094,21 +1094,21 @@ def coerce_conditions(conditions)
10941094
# @api private
10951095
#
10961096
# rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/CyclomaticComplexity
1097-
def __join__(type, other, join_cond = EMPTY_HASH, opts = EMPTY_HASH, &block)
1097+
def __join__(type, other, join_cond = EMPTY_HASH, opts = EMPTY_HASH, &)
10981098
if other.is_a?(Symbol) || other.is_a?(ROM::Relation::Name)
1099-
if join_cond.equal?(EMPTY_HASH) && !block
1099+
if join_cond.equal?(EMPTY_HASH) && !block_given?
11001100
assoc = associations[other]
11011101
assoc.join(type, self)
1102-
elsif block
1103-
__join__(type, other, JoinDSL.new(schema).(&block), opts)
1102+
elsif block_given?
1103+
__join__(type, other, JoinDSL.new(schema).(&), opts)
11041104
else
1105-
new(dataset.__send__(type, other.to_sym, join_cond, opts, &block))
1105+
new(dataset.__send__(type, other.to_sym, join_cond, opts, &))
11061106
end
1107-
elsif other.is_a?(Sequel::SQL::AliasedExpression)
1108-
new(dataset.__send__(type, other, join_cond, opts, &block))
1107+
elsif other.is_a?(::Sequel::SQL::AliasedExpression)
1108+
new(dataset.__send__(type, other, join_cond, opts, &))
11091109
elsif other.respond_to?(:name) && other.name.is_a?(Relation::Name)
11101110
if block
1111-
join_cond = JoinDSL.new(schema).(&block)
1111+
join_cond = JoinDSL.new(schema).(&)
11121112

11131113
if other.name.aliaz
11141114
join_opts = { table_alias: other.name.aliaz }

lib/rom/sql/schema.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ def qualified_projection(table_alias = nil)
8787
# @return [Schema] A new schema with projected attributes
8888
#
8989
# @api public
90-
def project(*names, &block)
91-
if block
92-
super(*(names + ProjectionDSL.new(self).(&block)))
90+
def project(*names, &)
91+
if block_given?
92+
super(*(names + ProjectionDSL.new(self).(&)))
9393
else
9494
super
9595
end

spec/spec_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ module Types
117117
include Dry.Types(default: :strict)
118118
end
119119

120-
def with_adapters(*args, &block)
120+
def with_adapters(*args, &)
121121
reset_adapter = Hash[*ADAPTERS.flat_map { |a| [a, false] }]
122122
adapters = args.empty? || args[0] == :all ? ADAPTERS : (args & ADAPTERS)
123123

124124
adapters.each do |adapter|
125-
context("with #{adapter}", **reset_adapter, adapter => true, &block)
125+
context("with #{adapter}", **reset_adapter, adapter => true, &)
126126
end
127127
end
128128

spec/unit/relation/instrument_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def initialize
1515
@logs = []
1616
end
1717

18-
def instrument(*args, &block)
18+
def instrument(*args, &)
1919
logs << args
20-
block.call
20+
yield
2121
end
2222
end.new
2323
end

0 commit comments

Comments
 (0)