Class: Ast::Merge::Runtime::Operation

Inherits:
Object
  • Object
show all
Defined in:
lib/ast/merge/runtime/operation.rb

Overview

One merge attempt over one owned surface.

Instance Attribute Summary collapse

Instance Method Summary collapse

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 = options.dup.freeze
  @result = result
  @diagnostics = Array(diagnostics).dup
  @children = Array(children).dup
  @delegate_name = nil
  @status = status.to_sym
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



8
9
10
# File 'lib/ast/merge/runtime/operation.rb', line 8

def children
  @children
end

#delegate_nameObject (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_fragmentObject (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

#diagnosticsObject (readonly)

Returns the value of attribute diagnostics.



8
9
10
# File 'lib/ast/merge/runtime/operation.rb', line 8

def diagnostics
  @diagnostics
end

#operation_idObject (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

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/ast/merge/runtime/operation.rb', line 8

def options
  @options
end

#requested_strategyObject (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

#resultObject (readonly)

Returns the value of attribute result.



8
9
10
# File 'lib/ast/merge/runtime/operation.rb', line 8

def result
  @result
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/ast/merge/runtime/operation.rb', line 8

def status
  @status
end

#surfaceObject (readonly)

Returns the value of attribute surface.



8
9
10
# File 'lib/ast/merge/runtime/operation.rb', line 8

def surface
  @surface
end

#template_fragmentObject (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

Returns:

  • (Boolean)


84
85
86
# File 'lib/ast/merge/runtime/operation.rb', line 84

def completed?
  status == :completed
end

#delegate_assigned?Boolean

Returns:

  • (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

Returns:

  • (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_hObject



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: 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

Returns:

  • (Boolean)


92
93
94
# File 'lib/ast/merge/runtime/operation.rb', line 92

def unresolved?
  status == :unresolved
end