Sha256: 915eea20ff468ec808074de32af182ca393180e22db03e8dcf51262c0989312c

Contents?: true

Size: 1 KB

Versions: 9

Compression:

Stored size: 1 KB

Contents

module Hyperstack
  module Internal
    module Store
      module DispatchReceiver

        attr_accessor :params

        def receives(*args, &block)
          # Format the callback to be Proc or Nil
          callback = format_callback(args)

          if args.empty?
            message = 'At least one operation must be passed in to the \'receives\' macro'
            raise Legacy::Store::InvalidOperationError, message
          end

          # Loop through receivers and call callback and block on dispatch
          args.each do |operation|
            operation.on_dispatch do |params|
              @params = params

              callback.call if callback
              yield params if block
            end
          end
        end

        private

        def format_callback(args)
          if args.last.is_a?(Symbol)
            method_name = args.pop
            -> { send(:"#{method_name}") }
          elsif args.last.is_a?(Proc)
            args.pop
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
hyper-store-1.0.alpha1.8 lib/hyperstack/internal/store/dispatch_receiver.rb
hyper-store-1.0.alpha1.7 lib/hyperstack/internal/store/dispatch_receiver.rb
hyper-store-1.0.alpha1.6 lib/hyperstack/internal/store/dispatch_receiver.rb
hyper-store-1.0.alpha1.5 lib/hyperstack/internal/store/dispatch_receiver.rb
hyper-store-1.0.alpha1.4 lib/hyperstack/internal/store/dispatch_receiver.rb
hyper-store-1.0.alpha1.3 lib/hyperstack/internal/store/dispatch_receiver.rb
hyper-store-1.0.alpha1.2 lib/hyperstack/internal/store/dispatch_receiver.rb
hyper-store-1.0.alpha1.1 lib/hyperstack/internal/store/dispatch_receiver.rb
hyper-store-1.0.alpha1 lib/hyperstack/internal/store/dispatch_receiver.rb