Sha256: fd9274bba1801af983b31ecd900caf1f38b0593c0c4be544d03515230d3f9257

Contents?: true

Size: 1.18 KB

Versions: 4

Compression:

Stored size: 1.18 KB

Contents

require 'bugsnag'

Rake::TaskManager.record_task_metadata = true

module Bugsnag::Rake
  def self.included(base)
    base.extend ClassMethods
    base.class_eval do
      class << self
        alias_method :original_define_task, :define_task
        alias_method :define_task, :bugsnag_define_task
      end
    end

    Bugsnag.before_notify_callbacks << lambda {|notif|
      task = Thread.current[:bugsnag_running_task]
      next unless task

      notif.add_tab(:rake_task, {
        :name => task.name,
        :description => task.full_comment,
        :arguments => task.arg_description
      })

      notif.context ||= task.name
    }
  end

  module ClassMethods
    def bugsnag_define_task(*args, &block)
      task = self.original_define_task(*args) do |*block_args|
        begin
          old_task = Thread.current[:bugsnag_running_task]
          Thread.current[:bugsnag_running_task] = task

          yield(*block_args) if block_given?
        rescue Exception => e
          Bugsnag.auto_notify(e)
          raise
        ensure
          Thread.current[:bugsnag_running_task] = old_task
        end
      end
    end
  end
end

Rake::Task.send(:include, Bugsnag::Rake) if defined?(Rake::Task)

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bugsnag-2.7.1 lib/bugsnag/rake.rb
bugsnag-2.7.0 lib/bugsnag/rake.rb
bugsnag-2.6.1 lib/bugsnag/rake.rb
bugsnag-2.6.0 lib/bugsnag/rake.rb