Closed alexmobo closed 5 years ago
:+1:
Just ran into the same problem ;)
FYI, I came up with a slightly different solution: Undefine the methods based on the unique event names (see below). Not sure which is preferrable, yours might be more robust?
if respond_to? :inherited_workflow_spec # undefine methods defined by the old workflow_spec
state_values = inherited_workflow_spec.states.values
state_names = state_values.collect(&:name)
event_names = state_values.flat_map { |state| state.events.flat.collect(&:name) }.uniq
state_names.each do |state_name|
module_eval do
undef_method "#{state_name}?"
end
end
event_names.each do |event_name|
module_eval do
undef_method "#{event_name}!".to_sym
undef_method "can_#{event_name}?"
end
end
end
This code ensures that a class structure as:
Doesen´t raise an exception like:
This happens because
.workflow
method tries to undefine the same event more than once.