devdocs/lib/docs/subscribers/image_subscriber.rb
2017-07-16 17:43:14 -04:00

27 lines
812 B
Ruby

# frozen_string_literal: true
module Docs
class ImageSubscriber < Subscriber
self.namespace = 'image'
def broken(event)
log "Skipped broken image (#{event.payload[:code]}): #{event.payload[:url]}"
end
def invalid(event)
log "Skipped invalid image (#{event.payload[:content_type]}): #{event.payload[:url]}"
end
def too_big(event)
log "Skipped large image (#{(event.payload[:size] / 1_000.0).round} KB): #{event.payload[:url]}"
end
def error(event)
exception = event.payload[:exception]
log "ERROR: #{event.payload[:url]}"
puts " #{exception.class}: #{exception.message.gsub("\n", "\n ")}"
puts exception.backtrace.select { |line| line.start_with?(Docs.root_path) }.join("\n ").prepend("\n ")
puts "\n"
end
end
end