Method: Bake::Context#call

Defined in:
lib/bake/context.rb

#call(*commands) {||recipe, result| If a block is given, it will be called with the last recipe and its result. @parameter recipe [Recipe] The last recipe that was called. @parameter result [Object | Nil] The result of the last recipe.| ... } ⇒ Object

Invoke recipes on the context using command line arguments.

e.g. ‘context.call(“gem:release:version:increment”, “0,0,1”)`

Yields:

  • (|recipe, result| If a block is given, it will be called with the last recipe and its result. @parameter recipe [Recipe] The last recipe that was called. @parameter result [Object | Nil] The result of the last recipe.)

    |recipe, result| If a block is given, it will be called with the last recipe and its result. @parameter recipe [Recipe] The last recipe that was called. @parameter result [Object | Nil] The result of the last recipe.



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/bake/context.rb', line 97

def call(*commands, &block)
  recipe = nil
  last_result = nil
  
  # Invoke the recipes in the order they were specified:
  while command = commands.shift
    if recipe = @recipes[command]
      arguments, options = recipe.prepare(commands, last_result)
      last_result = recipe.call(*arguments, **options)
    else
      raise ArgumentError, "Could not find recipe for #{command}!"
    end
  end
  
  # If a block is given, we yield the last recipe and its result:
  if block_given?
    yield recipe, last_result
  end
  
  return last_result
end