Sha256: 775951c17127ca653b29c7583d1be17a4ba577f378ed717bb92b39add7a1304e
Contents?: true
Size: 1.25 KB
Versions: 12
Compression:
Stored size: 1.25 KB
Contents
module Hyperstack module Internal module Receiver class << self def mount(receiver, *args, &block) return if receiver.respond_to?(:unmounted?) && receiver.unmounted? # Format the callback to be Proc or Nil callback = format_callback(receiver, args) # Loop through receivers and call callback and/or block on dispatch args.each do |operation| id = operation.on_dispatch do |params| callback.call(params) if callback yield params if block end # TODO: broadcaster classes need to define unmount as well AutoUnmount.objects_to_unmount[receiver] << id if receiver.respond_to? :unmount end end def format_callback(receiver, args) call_back = if args.last.is_a?(Symbol) method_name = args.pop ->(*aargs) { receiver.send(:"#{method_name}", *aargs) } elsif args.last.is_a?(Proc) args.pop end return call_back unless args.empty? message = 'At least one operation must be passed in to the \'receives\' macro' raise Legacy::Store::InvalidOperationError, message end end end end end
Version data entries
12 entries across 12 versions & 1 rubygems