Class: JobWorkflow::TaskOutput
- Inherits:
-
Object
- Object
- JobWorkflow::TaskOutput
- Defined in:
- lib/job_workflow/task_output.rb,
sig/generated/job_workflow/task_output.rbs
Instance Attribute Summary collapse
- #data ⇒ Hash[Symbol, untyped] readonly
- #each_index ⇒ Integer readonly
- #task_name ⇒ Symbol readonly
Class Method Summary collapse
-
.deserialize(hash) ⇒ TaskOutput
: (Hash[String, untyped]) -> TaskOutput.
-
.from_task(task:, data:, each_index:) ⇒ TaskOutput
: (task: Task, each_index: Integer, data: Hash[Symbol, untyped]) -> TaskOutput.
Instance Method Summary collapse
-
#initialize(task_name:, each_index:, data: {}) ⇒ TaskOutput
constructor
: (task_name: Symbol, each_index: Integer, ?data: Hash[Symbol, untyped]) -> void.
-
#method_missing(name, *args, **kwargs, &block) ⇒ void
: ...
-
#respond_to_missing?(sym, include_private) ⇒ Boolean
: (Symbol, bool) -> bool.
-
#serialize ⇒ Hash[String, untyped]
: () -> Hash[String, untyped].
Constructor Details
#initialize(task_name:, each_index:, data: {}) ⇒ TaskOutput
: (task_name: Symbol, each_index: Integer, ?data: Hash[Symbol, untyped]) -> void
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
#data ⇒ Hash[Symbol, untyped] (readonly)
7 8 9 |
# File 'lib/job_workflow/task_output.rb', line 7 def data @data end |
#each_index ⇒ Integer (readonly)
6 7 8 |
# File 'lib/job_workflow/task_output.rb', line 6 def each_index @each_index end |
#task_name ⇒ Symbol (readonly)
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
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
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
49 50 51 |
# File 'lib/job_workflow/task_output.rb', line 49 def respond_to_missing?(sym, include_private) data.key?(sym) || super end |
#serialize ⇒ Hash[String, untyped]
: () -> 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 |