class Rake::Funnel::Integration::ProgressReport

Attributes

finished[R]
starting[R]

Public Class Methods

new() { |self| ... } click to toggle source
# File lib/rake/funnel/integration/progress_report.rb, line 11
def initialize
  task_starting do |task, _args|
    name = "[#{task.name}]".bold.cyan
    print "\n#{name}\n" unless Rake::Funnel::Integration::TeamCity.running?
  end

  yield self if block_given?

  patch.apply!
end

Public Instance Methods

disable!() click to toggle source
# File lib/rake/funnel/integration/progress_report.rb, line 30
def disable!
  patch.revert!
end
task_finished(&block) click to toggle source
# File lib/rake/funnel/integration/progress_report.rb, line 26
def task_finished(&block)
  @finished = block
end
task_starting(&block) click to toggle source
# File lib/rake/funnel/integration/progress_report.rb, line 22
def task_starting(&block)
  @starting = block
end

Private Instance Methods

create_patch() click to toggle source
# File lib/rake/funnel/integration/progress_report.rb, line 40
def create_patch # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  Rake::Funnel::Support::Patch.new(self) do |p|
    p.setup do |context|
      Rake::Task.class_eval do
        old_execute = instance_method(:execute)

        define_method(:execute) do |*args|
          context.starting.call(self, *args) if context.starting

          error = nil
          begin
            old_execute.bind(self).call(*args)
          rescue => e
            error = e
          ensure
            context.finished.call(self, *args, error) if context.finished
            raise error if error
          end
        end

        old_execute
      end
    end

    p.reset do |memo|
      Rake::Task.class_eval do
        define_method(:execute) do |*args|
          memo.bind(self).call(*args)
        end
      end
    end
  end
end
patch() click to toggle source
# File lib/rake/funnel/integration/progress_report.rb, line 36
def patch
  @patch ||= create_patch
end