Module: ActiveSupport::Notifications::Fanout::Subscribers

Defined in:
lib/active_support/notifications/fanout.rb

Overview

:nodoc:

Defined Under Namespace

Classes: AllMessages, EventObject, Evented, Matcher, MonotonicTimed, Timed

Class Method Summary collapse

Class Method Details

.new(pattern, listener, monotonic) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/active_support/notifications/fanout.rb', line 88

def self.new(pattern, listener, monotonic)
  subscriber_class = monotonic ? MonotonicTimed : Timed

  if listener.respond_to?(:start) && listener.respond_to?(:finish)
    subscriber_class = Evented
  else
    # Doing all this to detect a block like `proc { |x| }` vs
    # `proc { |*x| }` or `proc { |**x| }`
    if listener.respond_to?(:parameters)
      params = listener.parameters
      if params.length == 1 && params.first.first == :opt
        subscriber_class = EventObject
      end
    end
  end

  wrap_all pattern, subscriber_class.new(pattern, listener)
end

.wrap_all(pattern, subscriber) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/active_support/notifications/fanout.rb', line 107

def self.wrap_all(pattern, subscriber)
  unless pattern
    AllMessages.new(subscriber)
  else
    subscriber
  end
end