luckyframework / luckyframework/avram

Normalizing callbacks for escape-hatch usage

Open
#898 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Crystal
Stars
183
Forks
67
PR merge metrics
No merged PRs in 30d

Description

The current callbacks are `before_save`, `after_save`, `after_commit` for SaveOperation, `before_delete`, `after_delete` for DeleteOperation, and `before_run`, `after_run` for Operation. With the exception of `after_commit`, these all do the exact same thing in their perspective positions.

One thing we could do is make `before_save` and `before_delete` just call `before_run`. Likewise for `after_save` and `after_delete`. Then these essentially are just syntactic sugar aliases used for clarity and convention. The benefit here would be if you wanted something special to happen before any sort of operation, you could create a module that just calls `before_run` and include that in every operation type and it would work.

The `after_commit` works the same, but the issue is that it's called in a different spot. We wouldn't want this added in to the `after_run` chain.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the callback definitions for SaveOperation, DeleteOperation, and Operation, then trace where before_run, after_run, and after_commit are invoked. The refactor is done when before_save and before_delete share the before_run behavior, after_save and after_delete share after_run behavior, and after_commit remains separate at its existing point.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal
Domain
databases
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.