Class: Hyalite::EventPluginRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/hyalite/event_plugin/event_plugin_registry.rb

Instance Method Summary collapse

Constructor Details

#initialize(*plugins) ⇒ EventPluginRegistry

Returns a new instance of EventPluginRegistry.



3
4
5
6
7
8
# File 'lib/hyalite/event_plugin/event_plugin_registry.rb', line 3

def initialize(*plugins)
  @registration_name_modules = {}
  @registration_name_dependencies = {}
  @plugins = []
  plugins.each {|plugin| add_plugin(plugin) }
end

Instance Method Details

#[](registration_name) ⇒ Object



28
29
30
# File 'lib/hyalite/event_plugin/event_plugin_registry.rb', line 28

def [](registration_name)
  @registration_name_modules[registration_name]
end

#add_plugin(plugin) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/hyalite/event_plugin/event_plugin_registry.rb', line 10

def add_plugin(plugin)
  plugin.event_types.each do |key, dispatch_config|
    dispatch_config[:phasedRegistrationNames].each do |phase, registration_name|
      @registration_name_modules[registration_name] = plugin
      @registration_name_dependencies[registration_name] = dispatch_config[:dependencies]
    end
  end
  @plugins << plugin
end

#dependencies(registration_name) ⇒ Object



24
25
26
# File 'lib/hyalite/event_plugin/event_plugin_registry.rb', line 24

def dependencies(registration_name)
  @registration_name_dependencies[registration_name]
end

#extract_events(top_level_type, top_level_target, top_level_target_id, event) ⇒ Object



32
33
34
35
36
37
# File 'lib/hyalite/event_plugin/event_plugin_registry.rb', line 32

def extract_events(top_level_type, top_level_target, top_level_target_id, event)
  @plugins.each.with_object([]) do |plugin, events|
    synthetic_event = plugin.extract_event(top_level_type, top_level_target, top_level_target_id, event)
    events << synthetic_event if synthetic_event
  end
end

#include?(registration_name) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/hyalite/event_plugin/event_plugin_registry.rb', line 20

def include?(registration_name)
  @registration_name_modules.has_key? registration_name
end

#registration_namesObject



39
40
41
42
43
44
45
46
47
# File 'lib/hyalite/event_plugin/event_plugin_registry.rb', line 39

def registration_names
  @registrasion_names ||= Set.new.tap do |names|
    TOP_LEVEL_EVENTS_TO_DISPATCH_CONFIG.each_value do |value|
      value[:phasedRegistrationNames].each_value do |name|
        names << name
      end
    end
  end
end