Class: StateMachineChecker::Transition

Inherits:
Object
  • Object
show all
Defined in:
lib/state_machine_checker/transition.rb

Overview

A transition from one state to another

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, to, name) ⇒ Transition

Returns a new instance of Transition.

Parameters:

  • from (Symbol)

    the starting state.

  • to (Symbol)

    the ending state.

  • name (Symbol)

    the name of the transition.


9
10
11
12
13
# File 'lib/state_machine_checker/transition.rb', line 9

def initialize(from, to, name)
  @from = from
  @to = to
  @name = name
end

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from


4
5
6
# File 'lib/state_machine_checker/transition.rb', line 4

def from
  @from
end

#nameObject (readonly)

Returns the value of attribute name


4
5
6
# File 'lib/state_machine_checker/transition.rb', line 4

def name
  @name
end

#toObject (readonly)

Returns the value of attribute to


4
5
6
# File 'lib/state_machine_checker/transition.rb', line 4

def to
  @to
end

Instance Method Details

#==(other) ⇒ Object


28
29
30
31
32
33
# File 'lib/state_machine_checker/transition.rb', line 28

def ==(other)
  hash_attributes.all? { |attr|
    other.respond_to?(attr) &&
      other.public_send(attr) == public_send(attr)
  }
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)

35
36
37
# File 'lib/state_machine_checker/transition.rb', line 35

def eql?(other)
  other == self
end

#execute(instance) ⇒ Object

Execute the transition on an instance.

This assumes that the instance has a method corresponding to the transition name, and that that will return a boolean representing whether the transition was successful.

Parameters:

  • instance

    the instance to execute the transition on.


22
23
24
25
26
# File 'lib/state_machine_checker/transition.rb', line 22

def execute(instance)
  # TODO: calling the "bang" version (to raise on failure) is specific to
  # the state_machines gem.
  instance.public_send("#{name}!")
end

#hashObject


39
40
41
# File 'lib/state_machine_checker/transition.rb', line 39

def hash
  hash_attributes.map(&:hash).hash
end