Class: Events::SingleSubscriberEvent

Inherits:
Event
  • Object
show all
Defined in:
lib/events.rb

Overview

An event with a single subscriber

Instance Attribute Summary

Attributes inherited from Event

#callbacks

Instance Method Summary collapse

Methods inherited from Event

#initialize, #remove_callback

Constructor Details

This class inherits a constructor from Events::Event

Instance Method Details

#add_callback(&proc) ⇒ Object

Override of Event.add_callback



61
62
63
64
65
66
67
# File 'lib/events.rb', line 61

def add_callback(&proc)
  if callbacks.length == 1
    raise EventSubscriptionError, "Cannot add more than one callback to SingleSubscriberEvent"
  end

  super
end

#fire(*args) ⇒ Object

Override of Event.fire



70
71
72
73
74
75
76
77
# File 'lib/events.rb', line 70

def fire(*args)
  packed_result = super
  if packed_result.length == 0
    return nil
  else
    return packed_result.first
  end
end