Class: JobWorkflow::TaskOutput
- Inherits:
-
Object
- Object
- JobWorkflow::TaskOutput
- Defined in:
- lib/job_workflow/task_output.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
: Hash[Symbol, untyped].
-
#each_index ⇒ Object
readonly
: Integer.
-
#task_name ⇒ Object
readonly
: Symbol.
Class Method Summary collapse
-
.deserialize(hash) ⇒ Object
: (Hash[String, untyped]) -> TaskOutput.
-
.from_task(task:, data:, each_index:) ⇒ Object
: (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) ⇒ Object
: …
-
#respond_to_missing?(sym, include_private) ⇒ Boolean
: (Symbol, bool) -> bool.
-
#serialize ⇒ Object
: () -> Hash[String, untyped].
Constructor Details
#initialize(task_name:, each_index:, data: {}) ⇒ TaskOutput
: (task_name: Symbol, each_index: Integer, ?data: Hash[Symbol, untyped]) -> void
28 29 30 31 32 |
# File 'lib/job_workflow/task_output.rb', line 28 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) ⇒ Object
: …
40 41 42 43 44 |
# File 'lib/job_workflow/task_output.rb', line 40 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 ⇒ Object (readonly)
: Hash[Symbol, untyped]
7 8 9 |
# File 'lib/job_workflow/task_output.rb', line 7 def data @data end |
#each_index ⇒ Object (readonly)
: Integer
6 7 8 |
# File 'lib/job_workflow/task_output.rb', line 6 def each_index @each_index end |
#task_name ⇒ Object (readonly)
: Symbol
5 6 7 |
# File 'lib/job_workflow/task_output.rb', line 5 def task_name @task_name end |
Class Method Details
.deserialize(hash) ⇒ Object
: (Hash[String, untyped]) -> TaskOutput
18 19 20 21 22 23 24 |
# File 'lib/job_workflow/task_output.rb', line 18 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:) ⇒ Object
: (task: Task, each_index: Integer, data: Hash[Symbol, untyped]) -> TaskOutput
11 12 13 14 15 |
# File 'lib/job_workflow/task_output.rb', line 11 def from_task(task:, data:, each_index:) normalized_data = task.output.to_h { |output_def| [output_def.name, nil] } 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
47 48 49 |
# File 'lib/job_workflow/task_output.rb', line 47 def respond_to_missing?(sym, include_private) data.key?(sym) || super end |
#serialize ⇒ Object
: () -> Hash[String, untyped]
35 36 37 |
# File 'lib/job_workflow/task_output.rb', line 35 def serialize { "task_name" => task_name.to_s, "each_index" => each_index, "data" => ActiveJob::Arguments.serialize([data]).first } end |