Class: CircuitBreaker::Transition

Inherits:
Object
  • Object
show all
Defined in:
lib/circuit_breaker.rb

Overview

Represents a transition in the Petri net workflow Transitions connect places and can have guard conditions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, from:, to:) ⇒ Transition

Returns a new instance of Transition.



124
125
126
127
128
129
130
131
# File 'lib/circuit_breaker.rb', line 124

def initialize(name:, from:, to:)
  @name = name
  @from_state = from
  @to_state = to
  @input_arcs = []
  @output_arcs = []
  @guard = nil
end

Instance Attribute Details

#from_stateObject (readonly)

Returns the value of attribute from_state.



122
123
124
# File 'lib/circuit_breaker.rb', line 122

def from_state
  @from_state
end

#guardObject (readonly)

Returns the value of attribute guard.



122
123
124
# File 'lib/circuit_breaker.rb', line 122

def guard
  @guard
end

#input_arcsObject (readonly)

Returns the value of attribute input_arcs.



122
123
124
# File 'lib/circuit_breaker.rb', line 122

def input_arcs
  @input_arcs
end

#nameObject (readonly)

Returns the value of attribute name.



122
123
124
# File 'lib/circuit_breaker.rb', line 122

def name
  @name
end

#output_arcsObject (readonly)

Returns the value of attribute output_arcs.



122
123
124
# File 'lib/circuit_breaker.rb', line 122

def output_arcs
  @output_arcs
end

#to_stateObject (readonly)

Returns the value of attribute to_state.



122
123
124
# File 'lib/circuit_breaker.rb', line 122

def to_state
  @to_state
end

Instance Method Details

#add_input_arc(place, weight = 1) ⇒ Object



133
134
135
136
137
# File 'lib/circuit_breaker.rb', line 133

def add_input_arc(place, weight = 1)
  arc = Arc.new(place, self, weight)
  @input_arcs << arc
  arc
end

#add_output_arc(place, weight = 1) ⇒ Object



139
140
141
142
143
# File 'lib/circuit_breaker.rb', line 139

def add_output_arc(place, weight = 1)
  arc = Arc.new(self, place, weight)
  @output_arcs << arc
  arc
end

#can_fire?(token) ⇒ Boolean

Returns:

  • (Boolean)


154
155
156
157
# File 'lib/circuit_breaker.rb', line 154

def can_fire?(token)
  return true unless @guard
  @guard.call(token)
end

#enabled?Boolean

Returns:

  • (Boolean)


149
150
151
152
# File 'lib/circuit_breaker.rb', line 149

def enabled?
  return false unless @guard.nil? || @guard.call
  @input_arcs.all?(&:enabled?) && @output_arcs.all?(&:enabled?)
end

#set_guard(&block) ⇒ Object



145
146
147
# File 'lib/circuit_breaker.rb', line 145

def set_guard(&block)
  @guard = block
end