Module: Finity::ClassMethods

Defined in:
lib/finity.rb

Overview

Class methods to be injected into the including class upon inclusion.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#machineObject

Returns the value of attribute machine.



36
37
38
# File 'lib/finity.rb', line 36

def machine
  @machine
end

Instance Method Details

#eventsObject

Return the names of all registered events.



56
57
58
# File 'lib/finity.rb', line 56

def events
  @machine.events.map { |name, _| name }
end

#finity(options = {}, &block) ⇒ Object

Instantiate a new state machine for the including class by accepting a block with state and event (and subsequent transition) definitions.



46
47
48
# File 'lib/finity.rb', line 46

def finity options = {}, &block
  @machine = Machine.new self, options, &block
end

#inherited(klass) ⇒ Object

When inheriting this module, pass the registered machines to the inheriting class after executing potential parent inheritance logic.



40
41
42
# File 'lib/finity.rb', line 40

def inherited klass
  super and klass.machine = machine
end

#statesObject

Return the names of all registered states.



51
52
53
# File 'lib/finity.rb', line 51

def states
  @machine.states.map { |name, _| name }
end