Module: QDA::Subscriber

Overview

Any gui element that may need to modify its appearance in response to application updates may include the subscriber module. Instances of the class may then call the subscribe method to receive notification of changes.

Instance Method Summary collapse

Instance Method Details

#notify(ev, content = nil) ⇒ Object

receive notification that an event of type ev has been called, optionally passing content for additional information about the object the event concerned.



68
69
70
71
72
73
74
75
# File 'lib/weft/broadcaster.rb', line 68

def notify(ev, content = nil)
  receiver = "receive_#{ev}".intern
  if respond_to?(receiver)
    send(receiver, content)
  else
    warn "#{self} received unhandled event #{ev}"
  end
end

#subscribe(broadcaster, *events) ⇒ Object

Subscribe this object to the events events, which should be a list of symbols. For example, to receive notification of category changes and additions, the recipient shoudl call

subscribe(:category_changed, :category_added)

For every event type to which a subscriber subscribes, it should implement a corresponding receive_xxx method, where xxx is the name of the event type. To act upon category changes, the subscriber should implement receive_category_changed



86
87
88
# File 'lib/weft/broadcaster.rb', line 86

def subscribe(broadcaster, *events)
  broadcaster.add_subscriber(self, *events)
end