Class: SourceMonitor::Configuration::Events

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

Constant Summary collapse

CALLBACK_KEYS =
%i[after_item_created after_item_scraped after_fetch_completed].freeze

Instance Method Summary collapse

Constructor Details

#initializeEvents

Returns a new instance of Events.



8
9
10
11
# File 'lib/source_monitor/configuration/events.rb', line 8

def initialize
  @callbacks = Hash.new { |hash, key| hash[key] = [] }
  @item_processors = []
end

Instance Method Details

#callbacks_for(name) ⇒ Object



26
27
28
# File 'lib/source_monitor/configuration/events.rb', line 26

def callbacks_for(name)
  @callbacks[name.to_sym]&.dup || []
end

#item_processorsObject



30
31
32
# File 'lib/source_monitor/configuration/events.rb', line 30

def item_processors
  @item_processors.dup
end

#register_item_processor(processor = nil, &block) ⇒ Object



19
20
21
22
23
24
# File 'lib/source_monitor/configuration/events.rb', line 19

def register_item_processor(processor = nil, &block)
  callable = processor || block
  validate_callable!(callable, :item_processor)
  @item_processors << callable
  callable
end

#reset!Object



34
35
36
37
# File 'lib/source_monitor/configuration/events.rb', line 34

def reset!
  @callbacks.clear
  @item_processors.clear
end