Sha256: d0ad7d8d32fb4fbe40647d7523bbaa15162cfaffaed13630a52ffdfadfd8c316
Contents?: true
Size: 903 Bytes
Versions: 12
Compression:
Stored size: 903 Bytes
Contents
module HyperStore module DispatchReceiver class InvalidOperationError < StandardError; end 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 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
Version data entries
12 entries across 12 versions & 1 rubygems