Module: Scrolls::Rails

Extended by:
Rails
Included in:
Rails
Defined in:
lib/scrolls/rails.rb,
lib/scrolls/rails/version.rb,
lib/scrolls/rails/log_subscriber.rb,
lib/scrolls/rails/rack/quiet_logger.rb

Defined Under Namespace

Modules: Rack Classes: LogSubscriber

Constant Summary collapse

VERSION =
'0.0.1'

Instance Method Summary collapse

Instance Method Details

#detach_existing_subscribersObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/scrolls/rails.rb', line 21

def detach_existing_subscribers
  ActiveSupport::LogSubscriber.log_subscribers.each do |subscriber|
    case subscriber
    when ActionView::LogSubscriber
      unsubscribe(:action_view, subscriber)
    when ActionController::LogSubscriber
      unsubscribe(:action_controller, subscriber)
    end
  end
end

#events_for_subscriber(subscriber) ⇒ Object



47
48
49
# File 'lib/scrolls/rails.rb', line 47

def events_for_subscriber(subscriber)
  subscriber.public_methods(false).reject {|method| method.to_s == 'call' }
end

#setup(app) ⇒ Object



16
17
18
19
# File 'lib/scrolls/rails.rb', line 16

def setup(app)
  detach_existing_subscribers
  Scrolls::Rails::LogSubscriber.attach_to(:action_controller)
end

#unsubscribe(component, subscriber) ⇒ Object

private



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/scrolls/rails.rb', line 34

def unsubscribe(component, subscriber)
  events = events_for_subscriber(subscriber)

  events.each do |event|
    notifier = ActiveSupport::Notifications.notifier
    notifier.listeners_for("#{event}.#{component}").each do |listener|
      if listener.instance_variable_get('@delegate') == subscriber
        ActiveSupport::Notifications.unsubscribe(listener)
      end
    end
  end
end