Skip to content

Commit

Permalink
Merge pull request imdrasil#12 from vulk/master
Browse files Browse the repository at this point in the history
#imdrasil/issues/11 Dependencies don't receive arguments
  • Loading branch information
imdrasil authored Feb 20, 2020
2 parents f6cd575 117b5b2 commit 4d920cf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 9 additions & 0 deletions spec/task_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 45,15 @@ describe Sam::Task do
end
arr.empty?.should eq(true)
end
it "invokes dependencies with arguments" do
count = 0
namespace.task("t1") { |t, args|
count = args[0].as(Int32)
count = args["count"].as(Int32) }
namespace.task("t2", ["t1"]) { |t, args|
count = 1}.call(Sam::Args.new({"count" => 1}, [1]))
count.should eq(3)
end
end

context "no arguments" do
Expand Down
9 changes: 8 additions & 1 deletion src/sam/task.cr
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 32,14 @@ module Sam
# Launch current task. Prerequisites are invoked first.
def call(args : Args)
@invoked = true
@deps.each { |name| invoke(name) }
case @block.arity
when 0, 1
@deps.each { |name| invoke(name) }
when 2
@deps.each { |name| invoke(name, args) }
else
raise "Wrong task block arity - #{@block.arity} and maximum is 2."
end
case @block.arity
when 0
@block.as(-> Void).call
Expand Down

0 comments on commit 4d920cf

Please sign in to comment.