Class: ActiveHarness::Pipeline::Step

Inherits:
Object
  • Object
show all
Defined in:
lib/active_harness/pipeline/step.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, executor = nil, &block) ⇒ Step

Returns a new instance of Step.



6
7
8
9
10
11
# File 'lib/active_harness/pipeline/step.rb', line 6

def initialize(name, executor = nil, &block)
  @name     = name
  @executor = executor
  @stop_if  = nil
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#executorObject (readonly)

Returns the value of attribute executor.



4
5
6
# File 'lib/active_harness/pipeline/step.rb', line 4

def executor
  @executor
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/active_harness/pipeline/step.rb', line 4

def name
  @name
end

Instance Method Details

#extract_payload(result) ⇒ Object

Extract the new payload value from result. Uses the user-defined transform block when present; falls back to result.output.



57
58
59
# File 'lib/active_harness/pipeline/step.rb', line 57

def extract_payload(result)
  @transform_block ? @transform_block.call(result) : result.output
end

#lambda?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/active_harness/pipeline/step.rb', line 38

def lambda?
  @executor.is_a?(Proc)
end

#stop_if(lam = nil) ⇒ Object

DSL (inside block): stop_if ->(result) { … } Getter (external): step.stop_if → lambda or nil



20
21
22
# File 'lib/active_harness/pipeline/step.rb', line 20

def stop_if(lam = nil)
  lam ? @stop_if = lam : @stop_if
end

#transform(&block) ⇒ Object

DSL: define how to extract the new payload from a result. When provided, the step always updates the payload — even if stop_if is also set. The block receives the Result and must return the new payload value.

step :laundry do
  use PromptLaundryPipeline
  transform { |result| result.output }
  stop_if   ->(result) { result.processed["stopped"] == true }
end


33
34
35
36
# File 'lib/active_harness/pipeline/step.rb', line 33

def transform(&block)
  @transform_block = block if block
  @transform_block
end

#transform?Boolean

Returns true when this step should update the pipeline payload after execution. A step transforms when:

- an explicit transform block is defined (overrides default), OR
- no stop_if and not a tribunal (legacy default)

Returns:

  • (Boolean)


51
52
53
# File 'lib/active_harness/pipeline/step.rb', line 51

def transform?
  @transform_block ? true : (!tribunal? && @stop_if.nil?)
end

#tribunal?Boolean

True if the executor is a Tribunal subclass — tribunal steps do not update payload.

Returns:

  • (Boolean)


43
44
45
# File 'lib/active_harness/pipeline/step.rb', line 43

def tribunal?
  @executor.is_a?(Class) && @executor <= ActiveHarness::Tribunal
end

#use(klass) ⇒ Object

DSL: use TranslationAgent / SafetyTribunal / NestedPipeline



14
15
16
# File 'lib/active_harness/pipeline/step.rb', line 14

def use(klass)
  @executor = klass
end