Don't use tap so return value is that of yield

This commit is contained in:
Ary Borenszweig 2016-06-29 16:54:16 -03:00
parent 72431bb1d8
commit 038ffef33a
3 changed files with 12 additions and 23 deletions

View file

@ -102,14 +102,13 @@ module DB
# Same as `#open` but the database is yielded and closed automatically.
def self.open(uri : URI | String, &block)
build_database(uri).tap do |db|
db = build_database(uri)
begin
yield db
ensure
db.close
end
end
end
private def self.build_database(connection_string : String)
build_database(URI.parse(connection_string))

View file

@ -31,13 +31,8 @@ module DB
# The `ResultSet` is closed automatically.
def query(query, *args)
# CHECK prepare(query).query(*args, &block)
query(query, *args).tap do |rs|
begin
yield rs
ensure
rs.close
end
end
rs = query(query, *args)
yield rs ensure rs.close
end
# Performs the `query` and returns an `ExecResult`

View file

@ -69,19 +69,14 @@ module DB
# See `QueryMethods#query`
def query(*args)
query(*args).tap do |rs|
begin
yield rs
ensure
rs.close
end
end
rs = query(*args)
yield rs ensure rs.close
end
private def perform_exec_and_release(args : Enumerable) : ExecResult
perform_exec(args).tap do
res = perform_exec(args)
release_connection
end
res
end
protected abstract def perform_query(args : Enumerable) : ResultSet