Class: CircuitBreaker::Transition
- Inherits:
-
Object
- Object
- CircuitBreaker::Transition
- 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
-
#from_state ⇒ Object
readonly
Returns the value of attribute from_state.
-
#guard ⇒ Object
readonly
Returns the value of attribute guard.
-
#input_arcs ⇒ Object
readonly
Returns the value of attribute input_arcs.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#output_arcs ⇒ Object
readonly
Returns the value of attribute output_arcs.
-
#to_state ⇒ Object
readonly
Returns the value of attribute to_state.
Instance Method Summary collapse
- #add_input_arc(place, weight = 1) ⇒ Object
- #add_output_arc(place, weight = 1) ⇒ Object
- #can_fire?(token) ⇒ Boolean
- #enabled? ⇒ Boolean
-
#initialize(name:, from:, to:) ⇒ Transition
constructor
A new instance of Transition.
- #set_guard(&block) ⇒ Object
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_state ⇒ Object (readonly)
Returns the value of attribute from_state.
122 123 124 |
# File 'lib/circuit_breaker.rb', line 122 def from_state @from_state end |
#guard ⇒ Object (readonly)
Returns the value of attribute guard.
122 123 124 |
# File 'lib/circuit_breaker.rb', line 122 def guard @guard end |
#input_arcs ⇒ Object (readonly)
Returns the value of attribute input_arcs.
122 123 124 |
# File 'lib/circuit_breaker.rb', line 122 def input_arcs @input_arcs end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
122 123 124 |
# File 'lib/circuit_breaker.rb', line 122 def name @name end |
#output_arcs ⇒ Object (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_state ⇒ Object (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
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
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 |