class AASM::Base

def skip_instance_level_validation(event, name, aasm_name, klass)

def skip_instance_level_validation(event, name, aasm_name, klass)
  # Overrides the skip_validation config for an instance (If skip validation is set to false in original config) and
  # restores it back to the original value after the event is fired.
  safely_define_method klass, "#{name}_without_validation!", ->(*args, &block) do
    original_config = AASM::StateMachineStore.fetch(self.class, true).machine(aasm_name).config.skip_validation_on_save
    begin
      AASM::StateMachineStore.fetch(self.class, true).machine(aasm_name).config.skip_validation_on_save = true unless original_config
      aasm(aasm_name).current_event = :"#{name}!"
      aasm_fire_event(aasm_name, event, {:persist => true}, *args, &block)
    ensure
      AASM::StateMachineStore.fetch(self.class, true).machine(aasm_name).config.skip_validation_on_save = original_config
    end
  end
end