Sha256: eeaab3eeaa0ac926ad5449b534c531dcfff97c5c875cca3031e522f5f8c14085

Contents?: true

Size: 672 Bytes

Versions: 6

Compression:

Stored size: 672 Bytes

Contents

# frozen_string_literal: true

require 'dry/effects/effect'

module Dry
  module Effects
    module Effects
      class Interrupt < ::Module
        class InterruptEffect < Effect
          option :scope
        end

        def initialize(scope = :default)
          interrupt = InterruptEffect.new(type: :interrupt, scope: scope)

          module_eval do
            define_method(scope) do |payload = Undefined|
              if Undefined.equal?(payload)
                ::Dry::Effects.yield(interrupt)
              else
                ::Dry::Effects.yield(interrupt.(payload))
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dry-effects-0.1.3 lib/dry/effects/effects/interrupt.rb
dry-effects-0.1.2 lib/dry/effects/effects/interrupt.rb
dry-effects-0.1.1 lib/dry/effects/effects/interrupt.rb
dry-effects-0.1.0 lib/dry/effects/effects/interrupt.rb
dry-effects-0.1.0.alpha2 lib/dry/effects/effects/interrupt.rb
dry-effects-0.1.0.alpha lib/dry/effects/effects/interrupt.rb