Sha256: f46e4278cc94b3cfc7ff38e5185e515f2e55132d7d6d015a1922fac75b990c35

Contents?: true

Size: 978 Bytes

Versions: 2

Compression:

Stored size: 978 Bytes

Contents

module Finite
  # Get's the current state
  # @return the current state for an object
  def current_state
    machine = StateMachine.machines[self.class]
    @current_state or machine.states[machine.initial]
  end

  # Get's (and sets) the array of states
  # @return the array of states
  def states
    @states ||= StateMachine.machines[self.class].states
    @states
  end

  # Get's (and sets) the array of events
  # @return the array of events
  def events
    @events ||= StateMachine.machines[self.class].events
    @events
  end

  # Get's (and sets) the array of callbacks
  # @return the array of callbacks
  def callbacks
    @callbacks ||= StateMachine.machines[self.class].callbacks
    @callbacks
  end

  # Get's all the possible events you can perform
  # @return any event that you can perform given your state
  def possible_events
    pos = Array.new
    events.each_value{|event| pos << event if event.transitions.key?(current_state.name)}
    pos
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
finite-1.1.0 lib/finite/finite.rb
finite-1.0.0 lib/finite/finite.rb