Class: AutoShop

Inherits:
Object
  • Object
show all
Defined in:
auto_shop.rb

State Machines

This class contains 1 state machine(s).

state

State machine diagram for state

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) state

Gets the current attribute value for the machine

Returns:

  • The attribute value



4
5
6
7
8
9
10
11
12
# File 'auto_shop.rb', line 4

state_machine :initial => :available do
  event :tow_vehicle do
    transition :available => :busy
  end
  
  event :fix_vehicle do
    transition :busy => :available 
  end
end

Class Method Details

+ (String) human_state_event_name(event)

Gets the humanized name for the given event.

Parameters:

  • event (Symbol)

    The event to look up

Returns:

  • (String)

    The human event name



4
5
6
7
8
9
10
11
12
# File 'auto_shop.rb', line 4

state_machine :initial => :available do
  event :tow_vehicle do
    transition :available => :busy
  end
  
  event :fix_vehicle do
    transition :busy => :available 
  end
end

+ (String) human_state_name(state)

Gets the humanized name for the given state.

Parameters:

  • state (Symbol)

    The state to look up

Returns:

  • (String)

    The human state name



4
5
6
7
8
9
10
11
12
# File 'auto_shop.rb', line 4

state_machine :initial => :available do
  event :tow_vehicle do
    transition :available => :busy
  end
  
  event :fix_vehicle do
    transition :busy => :available 
  end
end

Instance Method Details

- (Boolean) available?

Checks whether :available is the current state.

Returns:

  • (Boolean)

    true if this is the current state, otherwise false



4
5
6
7
8
9
10
11
12
# File 'auto_shop.rb', line 4

state_machine :initial => :available do
  event :tow_vehicle do
    transition :available => :busy
  end
  
  event :fix_vehicle do
    transition :busy => :available 
  end
end

- (Boolean) busy?

Checks whether :busy is the current state.

Returns:

  • (Boolean)

    true if this is the current state, otherwise false



4
5
6
7
8
9
10
11
12
# File 'auto_shop.rb', line 4

state_machine :initial => :available do
  event :tow_vehicle do
    transition :available => :busy
  end
  
  event :fix_vehicle do
    transition :busy => :available 
  end
end

- (Boolean) can_fix_vehicle?(requirements = {})

Checks whether :fix_vehicle can be fired.

Parameters:

  • requirements (Hash) (defaults to: {})

    The transition requirements to test against

Options Hash (requirements):

  • :from (Symbol) — default: the current state

    One or more initial states

  • :to (Symbol)

    One or more target states

  • :guard (Boolean)

    Whether to guard transitions with conditionals

Returns:

  • (Boolean)

    true if :fix_vehicle can be fired, otherwise false



4
5
6
7
8
9
10
11
12
# File 'auto_shop.rb', line 4

state_machine :initial => :available do
  event :tow_vehicle do
    transition :available => :busy
  end
  
  event :fix_vehicle do
    transition :busy => :available 
  end
end

- (Boolean) can_tow_vehicle?(requirements = {})

Checks whether :tow_vehicle can be fired.

Parameters:

  • requirements (Hash) (defaults to: {})

    The transition requirements to test against

Options Hash (requirements):

  • :from (Symbol) — default: the current state

    One or more initial states

  • :to (Symbol)

    One or more target states

  • :guard (Boolean)

    Whether to guard transitions with conditionals

Returns:

  • (Boolean)

    true if :tow_vehicle can be fired, otherwise false



4
5
6
7
8
9
10
11
12
# File 'auto_shop.rb', line 4

state_machine :initial => :available do
  event :tow_vehicle do
    transition :available => :busy
  end
  
  event :fix_vehicle do
    transition :busy => :available 
  end
end

- (Boolean) fire_state_event(event, *args)

Fires an arbitrary state event with the given argument list

Parameters:

  • event (Symbol)

    The name of the event to fire

  • args

    Optional arguments to include in the transition

Returns:

  • (Boolean)

    true if the event succeeds, otherwise false



4
5
6
7
8
9
10
11
12
# File 'auto_shop.rb', line 4

state_machine :initial => :available do
  event :tow_vehicle do
    transition :available => :busy
  end
  
  event :fix_vehicle do
    transition :busy => :available 
  end
end

- (Boolean) fix_vehicle(*args)

Fires the :fix_vehicle event.

Parameters:

  • args (Array)

    Optional arguments to include in transition callbacks

Returns:

  • (Boolean)

    true if the transition succeeds, otherwise false



4
5
6
7
8
9
10
11
12
# File 'auto_shop.rb', line 4

state_machine :initial => :available do
  event :tow_vehicle do
    transition :available => :busy
  end
  
  event :fix_vehicle do
    transition :busy => :available 
  end
end

- (Boolean) fix_vehicle!(*args)

Fires the :fix_vehicle event, raising an exception if it fails.

Parameters:

  • args (Array)

    Optional arguments to include in transition callbacks

Returns:

  • (Boolean)

    true if the transition succeeds

Raises:

  • (StateMachine::InvalidTransition)

    If the transition fails



4
5
6
7
8
9
10
11
12
# File 'auto_shop.rb', line 4

state_machine :initial => :available do
  event :tow_vehicle do
    transition :available => :busy
  end
  
  event :fix_vehicle do
    transition :busy => :available 
  end
end

- (StateMachine::Transition) fix_vehicle_transition(requirements = {})

Gets the next transition that would be performed if :fix_vehicle were to be fired.

Parameters:

  • requirements (Hash) (defaults to: {})

    The transition requirements to test against

Options Hash (requirements):

  • :from (Symbol) — default: the current state

    One or more initial states

  • :to (Symbol)

    One or more target states

  • :guard (Boolean)

    Whether to guard transitions with conditionals

Returns:

  • (StateMachine::Transition)

    The transition that would be performed or nil



4
5
6
7
8
9
10
11
12
# File 'auto_shop.rb', line 4

state_machine :initial => :available do
  event :tow_vehicle do
    transition :available => :busy
  end
  
  event :fix_vehicle do
    transition :busy => :available 
  end
end

- (String) human_state_name

Gets the human-readable name of the state for the current value.

Returns:

  • (String)

    The human-readable state name



4
5
6
7
8
9
10
11
12
# File 'auto_shop.rb', line 4

state_machine :initial => :available do
  event :tow_vehicle do
    transition :available => :busy
  end
  
  event :fix_vehicle do
    transition :busy => :available 
  end
end

- (Boolean) state?(state_name)

Checks the given state name against the current state.

Parameters:

  • state_name (Symbol)

    The name of the state to check

Returns:

  • (Boolean)

    True if they are the same state, otherwise false

Raises:

  • (IndexError)

    If the state name is invalid



4
5
6
7
8
9
10
11
12
# File 'auto_shop.rb', line 4

state_machine :initial => :available do
  event :tow_vehicle do
    transition :available => :busy
  end
  
  event :fix_vehicle do
    transition :busy => :available 
  end
end

- (Array<Symbol>) state_events(requirements = {})

Gets the list of events that can be fired on the current state (uses the unqualified event names)

Parameters:

  • requirements (Hash) (defaults to: {})

    The transition requirements to test against

Options Hash (requirements):

  • :from (Symbol) — default: the current state

    One or more initial states

  • :to (Symbol)

    One or more target states

  • :on (Symbol)

    One or more events that fire the transition

  • :guard (Boolean)

    Whether to guard transitions with conditionals

Returns:

  • (Array<Symbol>)

    The list of event names



4
5
6
7
8
9
10
11
12
# File 'auto_shop.rb', line 4

state_machine :initial => :available do
  event :tow_vehicle do
    transition :available => :busy
  end
  
  event :fix_vehicle do
    transition :busy => :available 
  end
end

- (Symbol) state_name

Gets the internal name of the state for the current value.

Returns:

  • (Symbol)

    The internal name of the state



4
5
6
7
8
9
10
11
12
# File 'auto_shop.rb', line 4

state_machine :initial => :available do
  event :tow_vehicle do
    transition :available => :busy
  end
  
  event :fix_vehicle do
    transition :busy => :available 
  end
end

- (StateMachine::PathCollection) state_paths(requirements = {})

Gets the list of sequences of transitions that can be run for the current state

Parameters:

  • requirements (Hash) (defaults to: {})

    The transition requirements to test against

Options Hash (requirements):

  • :from (Symbol) — default: the current state

    The initial state

  • :to (Symbol)

    The target state

  • :deep (Boolean)

    Whether to enable deep searches for the target state

  • :guard (Boolean)

    Whether to guard transitions with conditionals

Returns:

  • (StateMachine::PathCollection)

    The collection of paths



4
5
6
7
8
9
10
11
12
# File 'auto_shop.rb', line 4

state_machine :initial => :available do
  event :tow_vehicle do
    transition :available => :busy
  end
  
  event :fix_vehicle do
    transition :busy => :available 
  end
end

- (Array<StateMachine::Transition>) state_transitions(requirements = {})

Gets the list of transitions that can be made for the current state

Parameters:

  • requirements (Hash) (defaults to: {})

    The transition requirements to test against

Options Hash (requirements):

  • :from (Symbol) — default: the current state

    One or more initial states

  • :to (Symbol)

    One or more target states

  • :on (Symbol)

    One or more events that fire the transition

  • :guard (Boolean)

    Whether to guard transitions with conditionals

Returns:

  • (Array<StateMachine::Transition>)

    The available transitions



4
5
6
7
8
9
10
11
12
# File 'auto_shop.rb', line 4

state_machine :initial => :available do
  event :tow_vehicle do
    transition :available => :busy
  end
  
  event :fix_vehicle do
    transition :busy => :available 
  end
end

- (Boolean) tow_vehicle(*args)

Fires the :tow_vehicle event.

Parameters:

  • args (Array)

    Optional arguments to include in transition callbacks

Returns:

  • (Boolean)

    true if the transition succeeds, otherwise false



4
5
6
7
8
9
10
11
12
# File 'auto_shop.rb', line 4

state_machine :initial => :available do
  event :tow_vehicle do
    transition :available => :busy
  end
  
  event :fix_vehicle do
    transition :busy => :available 
  end
end

- (Boolean) tow_vehicle!(*args)

Fires the :tow_vehicle event, raising an exception if it fails.

Parameters:

  • args (Array)

    Optional arguments to include in transition callbacks

Returns:

  • (Boolean)

    true if the transition succeeds

Raises:

  • (StateMachine::InvalidTransition)

    If the transition fails



4
5
6
7
8
9
10
11
12
# File 'auto_shop.rb', line 4

state_machine :initial => :available do
  event :tow_vehicle do
    transition :available => :busy
  end
  
  event :fix_vehicle do
    transition :busy => :available 
  end
end

- (StateMachine::Transition) tow_vehicle_transition(requirements = {})

Gets the next transition that would be performed if :tow_vehicle were to be fired.

Parameters:

  • requirements (Hash) (defaults to: {})

    The transition requirements to test against

Options Hash (requirements):

  • :from (Symbol) — default: the current state

    One or more initial states

  • :to (Symbol)

    One or more target states

  • :guard (Boolean)

    Whether to guard transitions with conditionals

Returns:

  • (StateMachine::Transition)

    The transition that would be performed or nil



4
5
6
7
8
9
10
11
12
# File 'auto_shop.rb', line 4

state_machine :initial => :available do
  event :tow_vehicle do
    transition :available => :busy
  end
  
  event :fix_vehicle do
    transition :busy => :available 
  end
end