Module: HyperStore::DispatchReceiver

Defined in:
lib/hyper-store/dispatch_receiver.rb

Defined Under Namespace

Classes: InvalidOperationError

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



5
6
7
# File 'lib/hyper-store/dispatch_receiver.rb', line 5

def params
  @params
end

Instance Method Details

#receives(*args, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/hyper-store/dispatch_receiver.rb', line 7

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 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