Class: Ast::Merge::Runtime::Operation
- Inherits:
-
Object
- Object
- Ast::Merge::Runtime::Operation
- Defined in:
- lib/ast/merge/runtime/operation.rb
Overview
One merge attempt over one owned surface.
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#delegate_name ⇒ Object
readonly
Returns the value of attribute delegate_name.
-
#destination_fragment ⇒ Object
readonly
Returns the value of attribute destination_fragment.
-
#diagnostics ⇒ Object
readonly
Returns the value of attribute diagnostics.
-
#operation_id ⇒ Object
readonly
Returns the value of attribute operation_id.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#requested_strategy ⇒ Object
readonly
Returns the value of attribute requested_strategy.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#surface ⇒ Object
readonly
Returns the value of attribute surface.
-
#template_fragment ⇒ Object
readonly
Returns the value of attribute template_fragment.
Instance Method Summary collapse
- #add_child(child_operation) ⇒ Object
- #add_diagnostic(diagnostic) ⇒ Object
- #assign_delegate!(delegate) ⇒ Object
- #complete!(result:) ⇒ Object
- #completed? ⇒ Boolean
- #delegate_assigned? ⇒ Boolean
- #fail!(diagnostic: nil) ⇒ Object
- #failed? ⇒ Boolean
-
#initialize(operation_id:, surface:, template_fragment:, destination_fragment:, requested_strategy: nil, options: {}, result: nil, diagnostics: [], children: [], status: :pending) ⇒ Operation
constructor
A new instance of Operation.
- #running! ⇒ Object
- #to_h ⇒ Object
- #unresolved!(result:, diagnostic: nil) ⇒ Object
- #unresolved? ⇒ Boolean
Constructor Details
#initialize(operation_id:, surface:, template_fragment:, destination_fragment:, requested_strategy: nil, options: {}, result: nil, diagnostics: [], children: [], status: :pending) ⇒ Operation
Returns a new instance of Operation.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ast/merge/runtime/operation.rb', line 20 def initialize( operation_id:, surface:, template_fragment:, destination_fragment:, requested_strategy: nil, options: {}, result: nil, diagnostics: [], children: [], status: :pending ) @operation_id = operation_id @surface = surface @template_fragment = template_fragment.to_s @destination_fragment = destination_fragment.to_s @requested_strategy = requested_strategy&.to_sym @options = .dup.freeze @result = result @diagnostics = Array(diagnostics).dup @children = Array(children).dup @delegate_name = nil @status = status.to_sym end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
8 9 10 |
# File 'lib/ast/merge/runtime/operation.rb', line 8 def children @children end |
#delegate_name ⇒ Object (readonly)
Returns the value of attribute delegate_name.
8 9 10 |
# File 'lib/ast/merge/runtime/operation.rb', line 8 def delegate_name @delegate_name end |
#destination_fragment ⇒ Object (readonly)
Returns the value of attribute destination_fragment.
8 9 10 |
# File 'lib/ast/merge/runtime/operation.rb', line 8 def destination_fragment @destination_fragment end |
#diagnostics ⇒ Object (readonly)
Returns the value of attribute diagnostics.
8 9 10 |
# File 'lib/ast/merge/runtime/operation.rb', line 8 def diagnostics @diagnostics end |
#operation_id ⇒ Object (readonly)
Returns the value of attribute operation_id.
8 9 10 |
# File 'lib/ast/merge/runtime/operation.rb', line 8 def operation_id @operation_id end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/ast/merge/runtime/operation.rb', line 8 def @options end |
#requested_strategy ⇒ Object (readonly)
Returns the value of attribute requested_strategy.
8 9 10 |
# File 'lib/ast/merge/runtime/operation.rb', line 8 def requested_strategy @requested_strategy end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
8 9 10 |
# File 'lib/ast/merge/runtime/operation.rb', line 8 def result @result end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
8 9 10 |
# File 'lib/ast/merge/runtime/operation.rb', line 8 def status @status end |
#surface ⇒ Object (readonly)
Returns the value of attribute surface.
8 9 10 |
# File 'lib/ast/merge/runtime/operation.rb', line 8 def surface @surface end |
#template_fragment ⇒ Object (readonly)
Returns the value of attribute template_fragment.
8 9 10 |
# File 'lib/ast/merge/runtime/operation.rb', line 8 def template_fragment @template_fragment end |
Instance Method Details
#add_child(child_operation) ⇒ Object
45 46 47 48 |
# File 'lib/ast/merge/runtime/operation.rb', line 45 def add_child(child_operation) @children << child_operation child_operation end |
#add_diagnostic(diagnostic) ⇒ Object
50 51 52 53 |
# File 'lib/ast/merge/runtime/operation.rb', line 50 def add_diagnostic(diagnostic) @diagnostics << diagnostic diagnostic end |
#assign_delegate!(delegate) ⇒ Object
60 61 62 63 |
# File 'lib/ast/merge/runtime/operation.rb', line 60 def assign_delegate!(delegate) @delegate_name = delegate&.name&.to_s self end |
#complete!(result:) ⇒ Object
65 66 67 68 69 |
# File 'lib/ast/merge/runtime/operation.rb', line 65 def complete!(result:) @result = result @status = :completed self end |
#completed? ⇒ Boolean
84 85 86 |
# File 'lib/ast/merge/runtime/operation.rb', line 84 def completed? status == :completed end |
#delegate_assigned? ⇒ Boolean
96 97 98 |
# File 'lib/ast/merge/runtime/operation.rb', line 96 def delegate_assigned? !delegate_name.nil? end |
#fail!(diagnostic: nil) ⇒ Object
78 79 80 81 82 |
# File 'lib/ast/merge/runtime/operation.rb', line 78 def fail!(diagnostic: nil) add_diagnostic(diagnostic) if diagnostic @status = :failed self end |
#failed? ⇒ Boolean
88 89 90 |
# File 'lib/ast/merge/runtime/operation.rb', line 88 def failed? status == :failed end |
#running! ⇒ Object
55 56 57 58 |
# File 'lib/ast/merge/runtime/operation.rb', line 55 def running! @status = :running self end |
#to_h ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/ast/merge/runtime/operation.rb', line 100 def to_h { operation_id: operation_id, surface: surface.respond_to?(:to_h) ? surface.to_h : surface, requested_strategy: requested_strategy, options: , result: result.respond_to?(:to_h) ? result.to_h : result, diagnostics: diagnostics.map { |diagnostic| diagnostic.respond_to?(:to_h) ? diagnostic.to_h : diagnostic }, children: children.map { |child| child.respond_to?(:operation_id) ? child.operation_id : child }, delegate_name: delegate_name, status: status }.compact end |
#unresolved!(result:, diagnostic: nil) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/ast/merge/runtime/operation.rb', line 71 def unresolved!(result:, diagnostic: nil) @result = result add_diagnostic(diagnostic) if diagnostic @status = :unresolved self end |
#unresolved? ⇒ Boolean
92 93 94 |
# File 'lib/ast/merge/runtime/operation.rb', line 92 def unresolved? status == :unresolved end |