Class: Downstream::Subscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/downstream/subscriber.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(event) ⇒ Object

Downstream subscriber interface



21
22
23
# File 'lib/downstream/subscriber.rb', line 21

def call(event)
  new.process_event(event)
end

.event_namesObject

All public names are considered event handlers (same concept as action_names in controllers/mailers)



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/downstream/subscriber.rb', line 8

def event_names
  @event_names ||= begin
    # All public instance methods of this class, including ancestors
    methods = (public_instance_methods(true) -
      # Except for public instance methods of Base and its ancestors
      Downstream.public_instance_methods(true) +
      # Be sure to include shadowed public instance methods of this class
      public_instance_methods(false)).uniq.map(&:to_s)
    methods.to_set
  end
end

Instance Method Details

#process_event(event) ⇒ Object



26
27
28
29
30
# File 'lib/downstream/subscriber.rb', line 26

def process_event(event)
  # TODO: callbacks? instrumentation?
  # TODO: namespaced events?
  public_send(event.type, event)
end