Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove bool return type restriction on Avram::Database#transaction #626

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/avram/database.cr
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ abstract class Avram::Database
def transaction : Bool
if current_transaction
yield
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, as a sort of "hack", we can leave the return type as Bool, but then add a true right after this line. The wrap_in_transaction method will already return the bool for that branch. This lets people put whatever in the block, and we still have that return type. The reason I say "hack" though is, i'm not a huge fan of just have a random static value just chillin there, but It would be a step in the right direction, and no different than what we're doing now 🤔

Copy link

@BrucePerens BrucePerens Mar 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better if this method was declared def transaction : Nil ? Anything that attempted to use the value would get a complaint. Oh, I guess Nil is falsey.

true
else
wrap_in_transaction do
yield
Expand Down