Class: ActiveSupport::Notifications::Fanout::Registry
Do not use. This class is for internal use only.
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | activesupport/lib/active_support/notifications/fanout.rb |
Overview
An immutable set of subscriptions, replaced rather than mutated, so that
it can be shared with other ::ActiveSupport::Ractors as a whole.
Constant Summary
-
NO_PATTERNS =
# File 'activesupport/lib/active_support/notifications/fanout.rb', line 61{}.freeze -
NO_SUBSCRIBERS =
# File 'activesupport/lib/active_support/notifications/fanout.rb', line 62[].freeze
Class Method Summary
Instance Attribute Summary
- #other_subscribers readonly
- #string_subscribers readonly
Instance Method Summary
Constructor Details
.new(string_subscribers = NO_PATTERNS, other_subscribers = NO_SUBSCRIBERS) ⇒ Registry
# File 'activesupport/lib/active_support/notifications/fanout.rb', line 66
def initialize(string_subscribers = NO_PATTERNS, other_subscribers = NO_SUBSCRIBERS) @string_subscribers = string_subscribers @other_subscribers = other_subscribers freeze end
Instance Attribute Details
#other_subscribers (readonly)
[ GitHub ]# File 'activesupport/lib/active_support/notifications/fanout.rb', line 64
attr_reader :string_subscribers, :other_subscribers
#string_subscribers (readonly)
[ GitHub ]# File 'activesupport/lib/active_support/notifications/fanout.rb', line 64
attr_reader :string_subscribers, :other_subscribers
Instance Method Details
#[](pattern)
[ GitHub ]# File 'activesupport/lib/active_support/notifications/fanout.rb', line 72
def [](pattern) @string_subscribers[pattern] || NO_SUBSCRIBERS end
#add(subscriber, prepend: false)
[ GitHub ]# File 'activesupport/lib/active_support/notifications/fanout.rb', line 80
def add(subscriber, prepend: false) pattern = subscriber.pattern if String === pattern listeners = self[pattern] with_pattern(pattern, prepend ? [subscriber, *listeners] : [*listeners, subscriber]) else with_other_subscribers([*@other_subscribers, subscriber]) end end
#delete(subscriber)
[ GitHub ]# File 'activesupport/lib/active_support/notifications/fanout.rb', line 91
def delete(subscriber) pattern = subscriber.try(:pattern) if String === pattern with_pattern(pattern, self[pattern] - [subscriber]) else with_other_subscribers(@other_subscribers - [subscriber]) end end
#delete_pattern(pattern)
[ GitHub ]# File 'activesupport/lib/active_support/notifications/fanout.rb', line 101
def delete_pattern(pattern) with_pattern(pattern, NO_SUBSCRIBERS) end
#size
[ GitHub ]# File 'activesupport/lib/active_support/notifications/fanout.rb', line 76
def size @string_subscribers.size + @other_subscribers.size end
#with_other_subscribers(other_subscribers) (private)
[ GitHub ]# File 'activesupport/lib/active_support/notifications/fanout.rb', line 117
def with_other_subscribers(other_subscribers) Registry.new(@string_subscribers, other_subscribers.freeze) end
#with_pattern(pattern, listeners) (private)
[ GitHub ]# File 'activesupport/lib/active_support/notifications/fanout.rb', line 106
def with_pattern(pattern, listeners) string_subscribers = if listeners.empty? @string_subscribers.except(pattern) else @string_subscribers.merge(pattern => listeners.freeze) end Registry.new(string_subscribers.freeze, @other_subscribers) end