Skip to content

Instantly share code, notes, and snippets.

@kainew
Created July 14, 2020 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kainew/bd655b16ffd9cb3037dbf3e5b835e65c to your computer and use it in GitHub Desktop.
Save kainew/bd655b16ffd9cb3037dbf3e5b835e65c to your computer and use it in GitHub Desktop.
Idealization codes for Donato's workflow
State
uid
name
possible_next_states
default_error_state
process [
update_status,
call_whatever,
...
]
State.possible_next_states.map(&:next_state)
State.flow(current_status, next_desired_state) {
can_change = current_status.possible_next_states.include(next_desired_state)
State.process.each.call(current_status, can_change, next_desired_state)
return can_change
}
update_status(current_status, can_change, next_desired_state) {
next_state = can_change? next_desired_state : current_status.default_error_state
State.update(current_state: next_desired_state)
workflow_log_create(current_state, next_desired_state, current_status)
}
workflow_log_create(current_state, next_desired_state, current_status){
WorkflowLog.create(current_state: current_state, next_desired_state: next_desired_state, current_status)
}
call_whatever(state_object, can_change, next_desired_state) { ... }
-------------
Model Before Create/Update...
check_workflow_actions
Do workflow changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment