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,12 +102,11 @@ module DB
# Same as `#open` but the database is yielded and closed automatically. # Same as `#open` but the database is yielded and closed automatically.
def self.open(uri : URI | String, &block) def self.open(uri : URI | String, &block)
build_database(uri).tap do |db| db = build_database(uri)
begin begin
yield db yield db
ensure ensure
db.close db.close
end
end end
end end

View file

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

View file

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