Class: JobWorkflow::TaskOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/job_workflow/task_output.rb,
sig/generated/job_workflow/task_output.rbs

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task_name:, each_index:, data: {}) ⇒ TaskOutput

: (task_name: Symbol, each_index: Integer, ?data: Hash[Symbol, untyped]) -> void

Parameters:

  • task_name: (Symbol)
  • each_index: (Integer)
  • data: (Hash[Symbol, untyped]) (defaults to: {})


30
31
32
33
34
# File 'lib/job_workflow/task_output.rb', line 30

def initialize(task_name:, each_index:, data: {})
  @task_name = task_name
  @each_index = each_index
  @data = data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, **kwargs, &block) ⇒ void

This method returns an undefined value.

: ...



42
43
44
45
46
# File 'lib/job_workflow/task_output.rb', line 42

def method_missing(name, *args, **kwargs, &block)
  return data[name.to_sym] if data.key?(name.to_sym) && args.empty? && kwargs.empty? && block.nil?

  super
end

Instance Attribute Details

#dataHash[Symbol, untyped] (readonly)

Signature:

  • Hash[Symbol, untyped]

Returns:

  • (Hash[Symbol, untyped])


7
8
9
# File 'lib/job_workflow/task_output.rb', line 7

def data
  @data
end

#each_indexInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


6
7
8
# File 'lib/job_workflow/task_output.rb', line 6

def each_index
  @each_index
end

#task_nameSymbol (readonly)

Signature:

  • Symbol

Returns:

  • (Symbol)


5
6
7
# File 'lib/job_workflow/task_output.rb', line 5

def task_name
  @task_name
end

Class Method Details

.deserialize(hash) ⇒ TaskOutput

: (Hash[String, untyped]) -> TaskOutput

Parameters:

  • (Hash[String, untyped])

Returns:



20
21
22
23
24
25
26
# File 'lib/job_workflow/task_output.rb', line 20

def deserialize(hash)
  new(
    task_name: hash["task_name"].to_sym,
    each_index: hash["each_index"],
    data: ActiveJob::Arguments.deserialize([hash["data"]]).first
  )
end

.from_task(task:, data:, each_index:) ⇒ TaskOutput

: (task: Task, each_index: Integer, data: Hash[Symbol, untyped]) -> TaskOutput

Parameters:

  • task: (Task)
  • each_index: (Integer)
  • data: (Hash[Symbol, untyped])

Returns:



11
12
13
14
15
16
17
# File 'lib/job_workflow/task_output.rb', line 11

def from_task(task:, data:, each_index:)
  normalized_data = task.output.to_h do |output_def|
    [output_def.name, nil] #: [Symbol, nil]
  end
  normalized_data.merge!(data.slice(*normalized_data.keys))
  new(task_name: task.task_name, each_index:, data: normalized_data)
end

Instance Method Details

#respond_to_missing?(sym, include_private) ⇒ Boolean

: (Symbol, bool) -> bool

Parameters:

  • (Symbol)
  • (Boolean)

Returns:

  • (Boolean)


49
50
51
# File 'lib/job_workflow/task_output.rb', line 49

def respond_to_missing?(sym, include_private)
  data.key?(sym) || super
end

#serializeHash[String, untyped]

: () -> Hash[String, untyped]

Returns:

  • (Hash[String, untyped])


37
38
39
# File 'lib/job_workflow/task_output.rb', line 37

def serialize
  { "task_name" => task_name.to_s, "each_index" => each_index, "data" => ActiveJob::Arguments.serialize([data]).first }
end