Module: Eventish::EventApi

Included in:
ActiveJobEvent, SimpleEvent
Defined in:
lib/eventish/event_api.rb

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object



5
6
7
# File 'lib/eventish/event_api.rb', line 5

def <=>(other)
  other&.priority <=> priority
end

#after_eventObject



9
10
11
# File 'lib/eventish/event_api.rb', line 9

def after_event
  Eventish.config.after_event || []
end

#before_eventObject



13
14
15
# File 'lib/eventish/event_api.rb', line 13

def before_event
  Eventish.config.before_event || []
end

#event_nameObject



17
18
19
# File 'lib/eventish/event_api.rb', line 17

def event_name
  @event_name ||= to_s
end

#priorityObject



21
22
23
# File 'lib/eventish/event_api.rb', line 21

def priority
  0
end

#subscribeObject



25
26
27
# File 'lib/eventish/event_api.rb', line 25

def subscribe
  Eventish.adapter.subscribe(event_name, self)
end

#subscribe_allObject



29
30
31
32
33
34
# File 'lib/eventish/event_api.rb', line 29

def subscribe_all
  ignore_events = [Eventish::SimpleEvent]
  ignore_events.push(Eventish::ActiveJobEvent) if defined? Eventish::ActiveJobEvent
  events = Eventish.descendants(self).sort
  (events - ignore_events).each(&:subscribe)
end

#unsubscribeObject



36
37
38
# File 'lib/eventish/event_api.rb', line 36

def unsubscribe
  Eventish.adapter.unsubscribe(event_name)
end