Skip to content

Commit

Permalink
crystal tool format with Crystal 1.15.0-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Oct 11, 2024
1 parent ba73f09 commit 25f7990
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions spec/dummy_driver.cr
Original file line number Diff line number Diff line change
Expand Up @@ -319,21 +319,21 @@ class Witness
end
end

def with_witness(count = 1)
def with_witness(count = 1, &)
w = Witness.new(count)
yield w
w.count.should eq(0), "The expected coverage was unmet"
end

def with_dummy(uri : String = "dummy://host?checkout_timeout=0.5")
def with_dummy(uri : String = "dummy://host?checkout_timeout=0.5", &)
DummyDriver::DummyConnection.clear_connections

DB.open uri do |db|
yield db
end
end

def with_dummy_connection(options = "")
def with_dummy_connection(options = "", &)
with_dummy("dummy://host?checkout_timeout=0.5&#{options}") do |db|
db.using_connection do |cnn|
yield cnn.as(DummyDriver::DummyConnection)
Expand Down
2 changes: 1 addition & 1 deletion spec/pool_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ShouldSleepingOp
@sleep_happened = Channel(Nil).new
end

def should_sleep
def should_sleep(&)
s = self
@is_sleeping = true
spawn do
Expand Down
4 changes: 2 additions & 2 deletions spec/save_point_transaction_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ require "./spec_helper"
private class FooException < Exception
end

private def with_dummy_top_transaction
private def with_dummy_top_transaction(&)
with_dummy_connection do |cnn|
cnn.transaction do |tx|
yield tx.as(DummyDriver::DummyTransaction), cnn
end
end
end

private def with_dummy_nested_transaction
private def with_dummy_nested_transaction(&)
with_dummy_connection do |cnn|
cnn.transaction do |tx|
tx.transaction do |nested|
Expand Down
4 changes: 2 additions & 2 deletions spec/support/http.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "http"
require "./fibers"

def wait_for(timeout = 5.seconds)
def wait_for(timeout = 5.seconds, &)
now = Time.monotonic

until yield
Expand All @@ -22,7 +22,7 @@ end
# shut down before continuing execution in the current fiber.
# 6. If the listening fiber raises an exception, it is rescued and re-raised
# in the current fiber.
def run_server(server)
def run_server(server, &)
server_done = Channel(Exception?).new

f = spawn do
Expand Down
2 changes: 1 addition & 1 deletion src/db.cr
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ module DB
connection_options = driver.connection_options(params)
pool_options = driver.pool_options(params)
builder = driver.connection_builder(uri)
factory = ->{ builder.build }
factory = -> { builder.build }
Database.new(connection_options, pool_options, &factory)
end

Expand Down
8 changes: 4 additions & 4 deletions src/db/database.cr
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module DB
# This covers more advanced use cases that might not be supported by an URI connection string such as tunneling connection.
def initialize(connection_options : Connection::Options, pool_options : Pool::Options, &factory : -> Connection)
@connection_options = connection_options
@setup_connection = ->(conn : Connection) {}
@setup_connection = ->(conn : Connection) { }
@pool = uninitialized Pool(Connection) # in order to use self in the factory proc
@pool = Pool(Connection).new(pool_options) {
conn = factory.call
Expand Down Expand Up @@ -111,7 +111,7 @@ module DB
# yields a connection from the pool
# the connection is returned to the pool
# when the block ends
def using_connection
def using_connection(&)
connection = self.checkout
begin
yield connection
Expand All @@ -131,7 +131,7 @@ module DB

# yields a `Transaction` from a connection of the pool
# Refer to `BeginTransaction#transaction` for documentation.
def transaction
def transaction(&)
using_connection do |cnn|
cnn.transaction do |tx|
yield tx
Expand All @@ -140,7 +140,7 @@ module DB
end

# :nodoc:
def retry
def retry(&)
@pool.retry do
yield
end
Expand Down
2 changes: 1 addition & 1 deletion src/db/enumerable_concat.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module DB
def initialize(@e1 : T, @e2 : U)
end

def each
def each(&)
if e1 = @e1
@e1.each do |e|
yield e
Expand Down
8 changes: 4 additions & 4 deletions src/db/pool.cr
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ module DB
# Will retry the block if a `ConnectionLost` exception is thrown.
# It will try to reuse all of the available connection right away,
# but if a new connection is needed there is a `retry_delay` seconds delay.
def retry
def retry(&)
current_available = 0

sync do
Expand Down Expand Up @@ -217,7 +217,7 @@ module DB
end

# :nodoc:
def each_resource
def each_resource(&)
sync do
@idle.each do |resource|
yield resource
Expand Down Expand Up @@ -265,7 +265,7 @@ module DB
end
end

private def sync
private def sync(&)
@mutex.lock
begin
yield
Expand All @@ -274,7 +274,7 @@ module DB
end
end

private def unsync
private def unsync(&)
@mutex.unlock
begin
yield
Expand Down
2 changes: 1 addition & 1 deletion src/db/pool_statement.cr
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module DB
# the conneciton is registered in `@connections`
private abstract def build_statement : Statement

private def statement_with_retry
private def statement_with_retry(&)
@db.retry do
return yield build_statement
end
Expand Down
4 changes: 2 additions & 2 deletions src/db/query_methods.cr
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module DB
# end
# end
# ```
def query(query, *args_, args : Enumerable? = nil)
def query(query, *args_, args : Enumerable? = nil, &)
# CHECK build(query).query(*args, &block)
rs = query(query, *args_, args: args)
yield rs ensure rs.close
Expand Down Expand Up @@ -262,7 +262,7 @@ module DB
# puts rs.read(String)
# end
# ```
def query_each(query, *args_, args : Enumerable? = nil)
def query_each(query, *args_, args : Enumerable? = nil, &)
query(query, *args_, args: args) do |rs|
rs.each do
yield rs
Expand Down
4 changes: 2 additions & 2 deletions src/db/result_set.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ module DB
# TODO add_next_result_set : Bool

# Iterates over all the rows
def each
def each(&)
while move_next
yield
end
end

# Iterates over all the columns
def each_column
def each_column(&)
column_count.times do |x|
yield column_name(x)
end
Expand Down
4 changes: 2 additions & 2 deletions src/db/statement.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module DB
end

# See `QueryMethods#query`
def query(*args_, args : Enumerable? = nil)
def query(*args_, args : Enumerable? = nil, &)
rs = query(*args_, args: args)
yield rs ensure rs.close
end
Expand Down Expand Up @@ -113,7 +113,7 @@ module DB
# This method is called when executing the statement. Although it can be
# redefined, it is recommended to use the `def_around_query_or_exec` macro
# to be able to add new behaviors without loosing prior existing ones.
protected def around_query_or_exec(args : Enumerable)
protected def around_query_or_exec(args : Enumerable, &)
yield
end

Expand Down
4 changes: 2 additions & 2 deletions src/db/string_key_cache.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ module DB
class StringKeyCache(T)
@cache = {} of String => T

def fetch(key : String) : T
def fetch(key : String, &) : T
value = @cache.fetch(key, nil)
value = @cache[key] = yield unless value
value
end

def each_value
def each_value(&)
@cache.each do |_, value|
yield value
end
Expand Down
8 changes: 4 additions & 4 deletions src/spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ module DB
class DriverSpecs(DBAnyType)
record ColumnDef, name : String, sql_type : String, null : Bool

@before : Proc(Nil) = ->{}
@after : Proc(Nil) = ->{}
@before : Proc(Nil) = -> { }
@after : Proc(Nil) = -> { }
@encode_null = "NULL"
@support_prepared = true
@support_unprepared = true
Expand Down Expand Up @@ -394,7 +394,7 @@ module DB
end

# :nodoc:
def with_db(options = nil)
def with_db(options = nil, &)
@before.call

if options
Expand Down Expand Up @@ -534,7 +534,7 @@ module DB
drop_table_if_exists_syntax.call(table_name)
end

def self.run(description = "as a db")
def self.run(description = "as a db", &)
ctx = self.new
with ctx yield ctx

Expand Down

0 comments on commit 25f7990

Please sign in to comment.