Class: Fosm::Lifecycle::EventDefinition
- Inherits:
-
Object
- Object
- Fosm::Lifecycle::EventDefinition
- Defined in:
- lib/fosm/lifecycle/event_definition.rb
Instance Attribute Summary collapse
-
#from_states ⇒ Object
readonly
Returns the value of attribute from_states.
-
#guards ⇒ Object
readonly
Returns the value of attribute guards.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#side_effects ⇒ Object
readonly
Returns the value of attribute side_effects.
-
#to_state ⇒ Object
readonly
Returns the value of attribute to_state.
Instance Method Summary collapse
- #add_guard(guard_def) ⇒ Object
- #add_side_effect(side_effect_def) ⇒ Object
-
#initialize(name:, from:, to:) ⇒ EventDefinition
constructor
A new instance of EventDefinition.
- #valid_from?(state) ⇒ Boolean
Constructor Details
#initialize(name:, from:, to:) ⇒ EventDefinition
Returns a new instance of EventDefinition.
6 7 8 9 10 11 12 |
# File 'lib/fosm/lifecycle/event_definition.rb', line 6 def initialize(name:, from:, to:) @name = name.to_sym @from_states = Array(from).map(&:to_sym) @to_state = to.to_sym @guards = [] @side_effects = [] end |
Instance Attribute Details
#from_states ⇒ Object (readonly)
Returns the value of attribute from_states.
4 5 6 |
# File 'lib/fosm/lifecycle/event_definition.rb', line 4 def from_states @from_states end |
#guards ⇒ Object (readonly)
Returns the value of attribute guards.
4 5 6 |
# File 'lib/fosm/lifecycle/event_definition.rb', line 4 def guards @guards end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/fosm/lifecycle/event_definition.rb', line 4 def name @name end |
#side_effects ⇒ Object (readonly)
Returns the value of attribute side_effects.
4 5 6 |
# File 'lib/fosm/lifecycle/event_definition.rb', line 4 def side_effects @side_effects end |
#to_state ⇒ Object (readonly)
Returns the value of attribute to_state.
4 5 6 |
# File 'lib/fosm/lifecycle/event_definition.rb', line 4 def to_state @to_state end |
Instance Method Details
#add_guard(guard_def) ⇒ Object
14 15 16 |
# File 'lib/fosm/lifecycle/event_definition.rb', line 14 def add_guard(guard_def) @guards << guard_def end |
#add_side_effect(side_effect_def) ⇒ Object
18 19 20 |
# File 'lib/fosm/lifecycle/event_definition.rb', line 18 def add_side_effect(side_effect_def) @side_effects << side_effect_def end |
#valid_from?(state) ⇒ Boolean
22 23 24 |
# File 'lib/fosm/lifecycle/event_definition.rb', line 22 def valid_from?(state) @from_states.include?(state.to_sym) end |