Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Fudge::Tasks::Task#initialize doesn't extract its options correctly. #84

Closed
KevinBrowne opened this issue Mar 11, 2014 · 0 comments · Fixed by #85
Closed

Fudge::Tasks::Task#initialize doesn't extract its options correctly. #84

KevinBrowne opened this issue Mar 11, 2014 · 0 comments · Fixed by #85

Comments

@KevinBrowne
Copy link
Member

Fudge::Tasks::Task#initialize copies and stores incoming arguments in the instance variable @args, and then extracts the options hash from the arguments and stores those in @options.

However, it extracts the options from the incoming arguments, not the copy in @args. Aside from the fact that #initialize alters its parameters—which is bad form—@args still retains the options hash, which is probably unintended.

This could affect a subclass that uses @args expecting—not unreasonably—that it doesn't include the options hash that was stored in @options.

Example (admittedly a little contrived):

# file: my_shell.rb
module Fudge
  module Tasks
    class MyShell
      def initialize(*args)
        super
        self.arguments = @args.join(' ')
      end
    end
    register MyShell
  end
end

# file: Fudgefile
build :default do
  task :my_shell, 'ls -l', foo: 'bar'
end

Running fudge with the above Fudgefile would result in

Running build default
Running task my_shell ls -l, {:foo=>"bar"}
ls: cannot access {:foo=: No such file or directory
Skipping callbacks...
Build FAILED!
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant