Class: Hatchet::ParentCondition

Inherits:
Object
  • Object
show all
Defined in:
lib/hatchet/conditions.rb

Overview

A condition based on parent task output

Examples:

Skip if parent output meets condition

Hatchet::ParentCondition.new(parent: start_task, expression: "output.random_number > 50")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent:, expression:) ⇒ ParentCondition

Returns a new instance of ParentCondition.

Parameters:

  • parent (Hatchet::Task, Symbol, String)

    The parent task reference

  • expression (String)

    CEL expression to evaluate



65
66
67
68
# File 'lib/hatchet/conditions.rb', line 65

def initialize(parent:, expression:)
  @parent = parent
  @expression = expression
end

Instance Attribute Details

#expressionString (readonly)

Returns CEL expression evaluated against the parent’s output.

Returns:

  • (String)

    CEL expression evaluated against the parent’s output



61
62
63
# File 'lib/hatchet/conditions.rb', line 61

def expression
  @expression
end

#parentHatchet::Task, ... (readonly)

Returns Reference to the parent task.

Returns:

  • (Hatchet::Task, Symbol, String)

    Reference to the parent task



58
59
60
# File 'lib/hatchet/conditions.rb', line 58

def parent
  @parent
end

Instance Method Details

#to_hHash

Returns:

  • (Hash)


71
72
73
74
75
76
77
78
# File 'lib/hatchet/conditions.rb', line 71

def to_h
  parent_name = case @parent
                when Symbol then @parent.to_s
                when String then @parent
                else @parent.respond_to?(:name) ? @parent.name.to_s : @parent.to_s
                end
  { type: "parent_condition", parent: parent_name, expression: @expression }
end