-
Notifications
You must be signed in to change notification settings - Fork 159
Open
Description
I propose adding the update_most_recent method to the Transition adapter module. This enhancement will help eliminate duplicated code and improve maintainability by providing a standard way to update the most recent transition on destruction.
Motivation:
Currently, users need to implement this logic themselves, resulting in duplicated code and potential errors. By adding this method to the core, we can ensure consistency and improve code quality.
At present, there are only two modules, ActiveRecordTransition and MemoryTransition. The proposed update is to add code duplication to the ActiveRecordTransition module.
after_destroy :update_most_recent, if: :most_recent?
private
def update_most_recent
last_transition = parent.send(transition_name).order(:sort_key).last
return unless last_transition.present?
last_transition.update_column(:most_recent, true)
endThe following code demonstrates how to use this method in a transition model:
include Statesman::Adapters::ActiveRecordTransition[transition_name: :transitions]