Class: ActiveJob::Temporal::ExternalOperation
- Inherits:
-
Object
- Object
- ActiveJob::Temporal::ExternalOperation
- Defined in:
- lib/activejob/temporal/external_operation.rb
Constant Summary collapse
- ACTIVITY =
"activity"- WORKFLOW =
"workflow"
Instance Attribute Summary collapse
-
#operation ⇒ Object
readonly
Returns the value of attribute operation.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#temporal_type ⇒ Object
readonly
Returns the value of attribute temporal_type.
Class Method Summary collapse
- .activity(temporal_type, **options) ⇒ Object
- .external_operation_hash?(value) ⇒ Boolean
- .normalize(value) ⇒ Object
- .normalize_hash(value) ⇒ Object
- .payload_value(payload, key) ⇒ Object
- .workflow(temporal_type, **options) ⇒ Object
Instance Method Summary collapse
-
#initialize(operation, temporal_type, options) ⇒ ExternalOperation
constructor
A new instance of ExternalOperation.
- #to_h ⇒ Object
Constructor Details
#initialize(operation, temporal_type, options) ⇒ ExternalOperation
Returns a new instance of ExternalOperation.
34 35 36 37 38 |
# File 'lib/activejob/temporal/external_operation.rb', line 34 def initialize(operation, temporal_type, ) @operation = normalize_operation(operation) @temporal_type = normalize_temporal_type(temporal_type) @options = ExternalOperationOptions.normalize(@operation, ) end |
Instance Attribute Details
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
11 12 13 |
# File 'lib/activejob/temporal/external_operation.rb', line 11 def operation @operation end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/activejob/temporal/external_operation.rb', line 11 def @options end |
#temporal_type ⇒ Object (readonly)
Returns the value of attribute temporal_type.
11 12 13 |
# File 'lib/activejob/temporal/external_operation.rb', line 11 def temporal_type @temporal_type end |
Class Method Details
.activity(temporal_type, **options) ⇒ Object
13 14 15 |
# File 'lib/activejob/temporal/external_operation.rb', line 13 def self.activity(temporal_type, **) new(ACTIVITY, temporal_type, ) end |
.external_operation_hash?(value) ⇒ Boolean
28 29 30 31 32 |
# File 'lib/activejob/temporal/external_operation.rb', line 28 def self.external_operation_hash?(value) value.respond_to?(:[]) && !payload_value(value, :temporal_operation).nil? && !payload_value(value, :temporal_type).nil? end |
.normalize(value) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/activejob/temporal/external_operation.rb', line 21 def self.normalize(value) return value.to_h if value.is_a?(self) return normalize_hash(value) if external_operation_hash?(value) nil end |
.normalize_hash(value) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/activejob/temporal/external_operation.rb', line 49 def normalize_hash(value) operation = payload_value(value, :temporal_operation) temporal_type = payload_value(value, :temporal_type) = payload_value(value, :options) || {} new(operation, temporal_type, ).to_h end |
.payload_value(payload, key) ⇒ Object
57 58 59 |
# File 'lib/activejob/temporal/external_operation.rb', line 57 def payload_value(payload, key) payload[key] || payload[key.to_s] end |
.workflow(temporal_type, **options) ⇒ Object
17 18 19 |
# File 'lib/activejob/temporal/external_operation.rb', line 17 def self.workflow(temporal_type, **) new(WORKFLOW, temporal_type, ) end |
Instance Method Details
#to_h ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/activejob/temporal/external_operation.rb', line 40 def to_h { temporal_operation: operation, temporal_type: temporal_type, options: .dup } end |