Sha256: 39d01cb619cc7fdf2b928d2a9178bea35a0cccfa974c731f486ef8705575aa82

Contents?: true

Size: 986 Bytes

Versions: 6

Compression:

Stored size: 986 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

6 entries across 6 versions & 1 rubygems

Version Path
hyper-operation-1.0.alpha1.5 lib/hyper-operation/railway/dispatcher.rb
hyper-operation-1.0.alpha1.4 lib/hyper-operation/railway/dispatcher.rb
hyper-operation-1.0.alpha1.3 lib/hyper-operation/railway/dispatcher.rb
hyper-operation-1.0.alpha1.2 lib/hyper-operation/railway/dispatcher.rb
hyper-operation-1.0.alpha1.1 lib/hyper-operation/railway/dispatcher.rb
hyper-operation-1.0.alpha1 lib/hyper-operation/railway/dispatcher.rb