Class: EvilEvents::Core::Events::ManagerRegistry Private
- Inherits:
-
Object
- Object
- EvilEvents::Core::Events::ManagerRegistry
- Extended by:
- Forwardable
- Defined in:
- lib/evil_events/core/events/manager_registry.rb,
lib/evil_events/core/events/manager_registry/scoped_event_type_matcher.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Classes: ScopedEventTypeMatcher
Instance Attribute Summary collapse
- #managers ⇒ Concurrent::Map readonly private
Instance Method Summary collapse
- #include?(manager) ⇒ Boolean private
-
#initialize ⇒ ManagerRegistry
constructor
private
A new instance of ManagerRegistry.
- #managed_event?(event_class) ⇒ Boolean private
- #managed_event_type?(event_type) ⇒ Boolean private private
- #managed_event_types ⇒ Array<String> private private
- #managed_events ⇒ Array<EvilEvents::Core::Events::AbstractEvent> private private
- #managed_events_map ⇒ Hash private
- #manager_of_event(event_class) ⇒ EvilEvents::Core::Events::Manager private
- #manager_of_event_type(event_type) ⇒ EvilEvents::Core::Events::Manager private
- #managers_of_event_condition(event_condition) ⇒ Array<EvilEvents::Core::Event::Manager> private
- #managers_of_event_pattern(event_pattern) ⇒ Array<EvilEvents::Core::Events::Manager> private
- #managers_of_scoped_event_type(scoped_event_type) ⇒ Array<EvilEvents::Core::Events::Manager> private
- #potential_manager_duplicate?(manager) ⇒ Boolean private private
-
#register(manager) ⇒ Object
private
Void.
-
#register_with(event_class) ⇒ Object
private
Void.
-
#unregister(manager) ⇒ Object
private
Void.
-
#unregister_with(event_class) ⇒ Object
private
Void.
Constructor Details
#initialize ⇒ ManagerRegistry
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ManagerRegistry.
19 20 21 |
# File 'lib/evil_events/core/events/manager_registry.rb', line 19 def initialize @managers = Concurrent::Map.new end |
Instance Attribute Details
#managers ⇒ Concurrent::Map (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/evil_events/core/events/manager_registry.rb', line 16 def managers @managers end |
Instance Method Details
#include?(manager) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
133 134 135 |
# File 'lib/evil_events/core/events/manager_registry.rb', line 133 def include?(manager) managed_event?(manager.event_class) && manager_of_event(manager.event_class) == manager end |
#managed_event?(event_class) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
141 142 143 |
# File 'lib/evil_events/core/events/manager_registry.rb', line 141 def managed_event?(event_class) managers.key?(event_class) end |
#managed_event_type?(event_type) ⇒ Boolean (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
174 175 176 |
# File 'lib/evil_events/core/events/manager_registry.rb', line 174 def managed_event_type?(event_type) managed_event_types.include?(event_type) end |
#managed_event_types ⇒ Array<String> (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
166 167 168 |
# File 'lib/evil_events/core/events/manager_registry.rb', line 166 def managed_event_types managed_events.map(&:type) end |
#managed_events ⇒ Array<EvilEvents::Core::Events::AbstractEvent> (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
159 160 161 |
# File 'lib/evil_events/core/events/manager_registry.rb', line 159 def managed_events managers.keys end |
#managed_events_map ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
148 149 150 151 152 |
# File 'lib/evil_events/core/events/manager_registry.rb', line 148 def managed_events_map managed_events.each_with_object({}) do |event, accumulator| accumulator[event.type] = event end end |
#manager_of_event(event_class) ⇒ EvilEvents::Core::Events::Manager
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
28 29 30 31 |
# File 'lib/evil_events/core/events/manager_registry.rb', line 28 def manager_of_event(event_class) # NOTE: raise exceptions to simplify runtime problems managers[event_class] || (raise EvilEvents::NonManagedEventClassError) end |
#manager_of_event_type(event_type) ⇒ EvilEvents::Core::Events::Manager
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 41 42 43 44 |
# File 'lib/evil_events/core/events/manager_registry.rb', line 38 def manager_of_event_type(event_type) event_class = managed_events.find do |managed_event| managed_event.type == event_type end manager_of_event(event_class) end |
#managers_of_event_condition(event_condition) ⇒ Array<EvilEvents::Core::Event::Manager>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
78 79 80 81 82 83 84 |
# File 'lib/evil_events/core/events/manager_registry.rb', line 78 def managers_of_event_condition(event_condition) event_classes = managed_events.select do |managed_event| !!event_condition.call(managed_event.type) end event_classes.map { |event_class| manager_of_event(event_class) } end |
#managers_of_event_pattern(event_pattern) ⇒ Array<EvilEvents::Core::Events::Manager>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
66 67 68 69 70 71 72 |
# File 'lib/evil_events/core/events/manager_registry.rb', line 66 def managers_of_event_pattern(event_pattern) event_classes = managed_events.select do |managed_event| managed_event.type.match(event_pattern) end event_classes.map { |event_class| manager_of_event(event_class) } end |
#managers_of_scoped_event_type(scoped_event_type) ⇒ Array<EvilEvents::Core::Events::Manager>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
52 53 54 55 56 57 58 59 60 |
# File 'lib/evil_events/core/events/manager_registry.rb', line 52 def managers_of_scoped_event_type(scoped_event_type) scope_matcher = ScopedEventTypeMatcher.new(scoped_event_type) event_classes = managed_events.select do |managed_event| scope_matcher.match?(managed_event.type) end event_classes.map { |event_class| manager_of_event(event_class) } end |
#potential_manager_duplicate?(manager) ⇒ Boolean (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
182 183 184 185 |
# File 'lib/evil_events/core/events/manager_registry.rb', line 182 def potential_manager_duplicate?(manager) return false unless managed_event?(manager.event_class) manager_of_event(manager.event_class).event_type == manager.event_type end |
#register(manager) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns void.
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/evil_events/core/events/manager_registry.rb', line 92 def register(manager) unless manager.is_a?(EvilEvents::Core::Events::Manager) raise EvilEvents::IncorrectManagerObjectError end if potential_manager_duplicate?(manager) || !managed_event_type?(manager.event_type) managers[manager.event_class] = manager else raise EvilEvents::AlreadyManagedEventClassError end end |
#register_with(event_class) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns void.
109 110 111 |
# File 'lib/evil_events/core/events/manager_registry.rb', line 109 def register_with(event_class) register(ManagerFactory.create(event_class)) end |
#unregister(manager) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns void.
117 118 119 |
# File 'lib/evil_events/core/events/manager_registry.rb', line 117 def unregister(manager) managers.delete_pair(manager.event_class, manager) end |
#unregister_with(event_class) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns void.
125 126 127 |
# File 'lib/evil_events/core/events/manager_registry.rb', line 125 def unregister_with(event_class) managers.delete(event_class) end |