Sha256: a40d19041ea130d16c9101799d33596c46d56f2621abfd654cdd866650904691

Contents?: true

Size: 770 Bytes

Versions: 1

Compression:

Stored size: 770 Bytes

Contents

# frozen_string_literal: true

module MtkFramework
  module ActiveInteractionConcerns
    module Interruptable
      extend ActiveSupport::Concern
      include ::MtkFramework::ActiveInteractionConcerns::Rescuable

      included do
        class ApplicationInterrupt < StandardError; end

        rescue_from ApplicationInterrupt do
          raise unless errors.any?
        end
      end

      def interrupt_execute!(*args)
        if args.any?
          if args[0].is_a? ActiveModel::Errors
            errors.merge!(args[0])
          else
            errors.add(args[0], args[1], **(args[2] || {}))
          end
        end

        raise 'interrupt_execute! called without error' if errors.empty?

        raise ApplicationInterrupt
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mtk_framework-1.0.1 lib/mtk_framework/active_interaction_concerns/interruptable.rb