Class: DeprecationToolkit::DeprecationSubscriber

Inherits:
ActiveSupport::Subscriber
  • Object
show all
Defined in:
lib/deprecation_toolkit/deprecation_subscriber.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.attach_to(gem_name, subscriber = new, notifier = ActiveSupport::Notifications, inherit_all: false) ⇒ Object



8
9
10
11
12
# File 'lib/deprecation_toolkit/deprecation_subscriber.rb', line 8

def attach_to(gem_name, subscriber = new, notifier = ActiveSupport::Notifications, inherit_all: false)
  return if already_attached_to?(gem_name)

  super(gem_name, subscriber, notifier, inherit_all: inherit_all)
end

.detach_from(gem_name, notifier = ActiveSupport::Notifications) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/deprecation_toolkit/deprecation_subscriber.rb', line 14

def detach_from(gem_name, notifier = ActiveSupport::Notifications)
  @namespace  = gem_name
  @subscriber = find_attached_subscriber(gem_name)
  @notifier = notifier

  return unless subscriber

  subscribers.delete(subscriber)

  # Remove event subscribers of all existing methods on the class.
  fetch_public_methods(subscriber, true).each do |event|
    remove_event_subscriber(event)
  end

  @notifier = nil unless any_subscribers_attached?
end

Instance Method Details

#deprecation(event) ⇒ Object



59
60
61
62
63
# File 'lib/deprecation_toolkit/deprecation_subscriber.rb', line 59

def deprecation(event)
  message = event.payload[:message]

  Collector.collect(message) unless deprecation_allowed?(event.payload)
end