Module: Hyperstack::Internal::Receiver
- Defined in:
- lib/hyperstack/internal/receiver.rb
Class Method Summary collapse
Class Method Details
.format_callback(receiver, args) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/hyperstack/internal/receiver.rb', line 21 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? = 'At least one operation must be passed in to the \'receives\' macro' raise Legacy::Store::InvalidOperationError, end |
.mount(receiver, *args, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/hyperstack/internal/receiver.rb', line 5 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 |