Sha256: b905a0cf70d02497a7732fc9a2fb847b2990b10cb54a0a38105bd4b2e93cc704

Contents?: true

Size: 985 Bytes

Versions: 3

Compression:

Stored size: 985 Bytes

Contents

module Hyperstack
  class Operation
    class Railway
      def receivers
        self.class.receivers
      end

      class << self
        def receivers
          # use the force: true option so that system code needing to receive
          # boot will NOT be erased on the next Hyperstack::Context.reset!
          Hyperstack::Context.set_var(self, :@receivers, force: true) { [] }
        end

        def add_receiver(&block)
          cloned_block = ->(*args, &b) { block.call(*args, &b) }
          operation = self
          cloned_block.define_singleton_method(:unmount) { operation.receivers.delete(cloned_block) }
          receivers << cloned_block
          cloned_block
        end
      end

      def dispatch
        result.then do
          receivers.each do |receiver|
            receiver.call(
              self.class.params_wrapper.dispatch_params(@operation.params),
              @operation
            )
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hyper-operation-1.0.alpha1.8 lib/hyper-operation/railway/dispatcher.rb
hyper-operation-1.0.alpha1.7 lib/hyper-operation/railway/dispatcher.rb
hyper-operation-1.0.alpha1.6 lib/hyper-operation/railway/dispatcher.rb