Class: Smith::Workflow::Graph::TransitionSnapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/smith/workflow/graph/transition_snapshot.rb

Constant Summary collapse

KINDS =
[
  %i[deterministic deterministic?],
  %i[router routed?],
  %i[nested_workflow nested?],
  %i[optimizer optimized?],
  %i[orchestrator orchestrated?],
  %i[parallel parallel?]
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**attributes) ⇒ TransitionSnapshot

Returns a new instance of TransitionSnapshot.



39
40
41
42
43
44
45
46
47
48
# File 'lib/smith/workflow/graph/transition_snapshot.rb', line 39

def initialize(**attributes)
  @name = attributes.fetch(:name)
  @from = attributes.fetch(:from)
  @to = attributes.fetch(:to)
  @kind = attributes.fetch(:kind)
  @success_transition = attributes[:success_transition]
  @failure_transition = attributes[:failure_transition]
  @routes = attributes[:routes]
  @fallback = attributes[:fallback]
end

Instance Attribute Details

#failure_transitionObject (readonly)

Returns the value of attribute failure_transition.



16
17
18
# File 'lib/smith/workflow/graph/transition_snapshot.rb', line 16

def failure_transition
  @failure_transition
end

#fallbackObject (readonly)

Returns the value of attribute fallback.



16
17
18
# File 'lib/smith/workflow/graph/transition_snapshot.rb', line 16

def fallback
  @fallback
end

#fromObject (readonly)

Returns the value of attribute from.



16
17
18
# File 'lib/smith/workflow/graph/transition_snapshot.rb', line 16

def from
  @from
end

#kindObject (readonly)

Returns the value of attribute kind.



16
17
18
# File 'lib/smith/workflow/graph/transition_snapshot.rb', line 16

def kind
  @kind
end

#nameObject (readonly)

Returns the value of attribute name.



16
17
18
# File 'lib/smith/workflow/graph/transition_snapshot.rb', line 16

def name
  @name
end

#routesObject (readonly)

Returns the value of attribute routes.



16
17
18
# File 'lib/smith/workflow/graph/transition_snapshot.rb', line 16

def routes
  @routes
end

#success_transitionObject (readonly)

Returns the value of attribute success_transition.



16
17
18
# File 'lib/smith/workflow/graph/transition_snapshot.rb', line 16

def success_transition
  @success_transition
end

#toObject (readonly)

Returns the value of attribute to.



16
17
18
# File 'lib/smith/workflow/graph/transition_snapshot.rb', line 16

def to
  @to
end

Class Method Details

.from_transition(transition) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/smith/workflow/graph/transition_snapshot.rb', line 18

def self.from_transition(transition)
  new(
    name: transition.name,
    from: transition.from,
    to: transition.to,
    kind: kind_for(transition),
    success_transition: transition.success_transition,
    failure_transition: transition.failure_transition,
    routes: transition.router_config&.fetch(:routes, nil),
    fallback: transition.router_config&.fetch(:fallback, nil)
  )
end

.kind_for(transition) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/smith/workflow/graph/transition_snapshot.rb', line 31

def self.kind_for(transition)
  kind = KINDS.find { |_name, predicate| transition.public_send(predicate) }
  return kind.first if kind
  return :agent if transition.agent_name

  :noop
end

Instance Method Details

#to_hObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/smith/workflow/graph/transition_snapshot.rb', line 50

def to_h
  {
    name: name,
    from: from,
    to: to,
    kind: kind,
    success_transition: success_transition,
    failure_transition: failure_transition,
    routes: routes,
    fallback: fallback
  }.compact
end