Skip to content

Commit

Permalink
Use Module.prepend instead of alias_method to patch Rake
Browse files Browse the repository at this point in the history
Libraries like Sentry that also patch Rake conflict with Airbrussh, due
to our use of `alias_method`. Fix by using `Module.prepend` instead,
when it is available (Ruby >= 2.0).

Fixes #151
  • Loading branch information
mattbrictson committed Sep 11, 2023
1 parent 65e611b commit 6a9b7ac
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lib/airbrussh/rake/context.rb
Expand Up @@ -13,6 +13,10 @@ module Rake
# for the `position` of a command.
#
class Context
class << self
attr_accessor :current_task_name
end

def initialize(config=Airbrussh.configuration)
@history = []
@enabled = config.monkey_patch_rake
Expand Down Expand Up @@ -47,10 +51,22 @@ def position(command)
history.index(command.to_s)
end

class << self
attr_accessor :current_task_name
if Object.respond_to?(:prepend)
module Patch
def execute(args=nil)
::Airbrussh::Rake::Context.current_task_name = name.to_s
super
end
end

def install_monkey_patch
def self.install_monkey_patch
require "rake"
return if ::Rake::Task.include?(::Airbrussh::Rake::Context::Patch)

::Rake::Task.prepend(::Airbrussh::Rake::Context::Patch)
end
else
def self.install_monkey_patch
require "rake"
return if ::Rake::Task.instance_methods.include?(:_airbrussh_execute)

Expand Down

0 comments on commit 6a9b7ac

Please sign in to comment.