From 1d9f3bcd8567a2847dbd9f81c0801803f3142ffd Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Wed, 21 Aug 2024 21:14:08 +1200 Subject: [PATCH] Add alias `Context#[]` to `Context#lookup`. --- lib/bake/context.rb | 3 +++ test/bake/context.rb | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/bake/context.rb b/lib/bake/context.rb index 1e1e33e..a3ad739 100644 --- a/lib/bake/context.rb +++ b/lib/bake/context.rb @@ -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. @@ -110,6 +111,8 @@ def lookup(command) @recipes[command] end + alias [] lookup + def to_s if @root "#{self.class} #{File.basename(@root)}" diff --git a/test/bake/context.rb b/test/bake/context.rb index 3d85cd9..8ca3197 100644 --- a/test/bake/context.rb +++ b/test/bake/context.rb @@ -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