Skip to content

Commit

Permalink
Add alias Context#[] to Context#lookup.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Aug 21, 2024
1 parent 61fc8dd commit 1d9f3bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/bake/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Copyright, 2020, by Olle Jonsson.

require_relative 'base'
require_relative 'registry'

module Bake
# The default file name for the top level bakefile.
Expand Down Expand Up @@ -110,6 +111,8 @@ def lookup(command)
@recipes[command]
end

alias [] lookup

def to_s
if @root
"#{self.class} #{File.basename(@root)}"
Expand Down
5 changes: 4 additions & 1 deletion test/bake/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
let(:context) {subject.load(bakefile)}

it 'can invoke root task' do
expect(context.lookup('doot')).to receive(:call)
recipe = context.lookup('doot')

expect(recipe).to receive(:call)
expect(recipe.instance).to receive(:doot)

context.call('doot')
end
Expand Down

0 comments on commit 1d9f3bc

Please sign in to comment.