Class: Braintrust::Task::Block

Inherits:
Object
  • Object
show all
Includes:
Braintrust::Task
Defined in:
lib/braintrust/task.rb

Overview

Block-based task. Stores a Proc and delegates #call to it. Includes Task so it satisfies Task === checks (e.g. in Context::Factory). Exposes #call_parameters so KeywordFilter can introspect the block’s declared kwargs rather than Block#call’s **kwargs signature.

Constant Summary

Constants included from Braintrust::Task

DEFAULT_NAME

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Braintrust::Task

included, new

Constructor Details

#initialize(name: DEFAULT_NAME, &block) ⇒ Block

Returns a new instance of Block.

Parameters:

  • name (String) (defaults to: DEFAULT_NAME)

    task name

  • block (Proc)

    task implementation



71
72
73
74
# File 'lib/braintrust/task.rb', line 71

def initialize(name: DEFAULT_NAME, &block)
  @name = name
  @block = wrap_block(block)
end

Instance Attribute Details

#nameString (readonly)

Returns:

  • (String)


67
68
69
# File 'lib/braintrust/task.rb', line 67

def name
  @name
end

Instance Method Details

#call(**kwargs) ⇒ Object

Returns result of the block.

Parameters:

  • kwargs (Hash)

    keyword arguments (filtered by KeywordFilter)

Returns:

  • (Object)

    result of the block



78
79
80
# File 'lib/braintrust/task.rb', line 78

def call(**kwargs)
  @block.call(**kwargs)
end

#call_parametersArray<Array>

Exposes the block’s parameter list so KeywordFilter can filter kwargs to match the block’s declared keywords.

Returns:

  • (Array<Array>)

    parameter list from Proc#parameters



85
86
87
# File 'lib/braintrust/task.rb', line 85

def call_parameters
  @block.parameters
end