class StateMachineChecker::Transition

A transition from one state to another

Attributes

from[R]
name[R]
to[R]

Public Class Methods

new(from, to, name) click to toggle source

@param [Symbol] from the starting state. @param [Symbol] to the ending state. @param [Symbol] name the name of the transition.

# File lib/state_machine_checker/transition.rb, line 9
def initialize(from, to, name)
  @from = from
  @to = to
  @name = name
end

Public Instance Methods

==(other) click to toggle source
# 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) click to toggle source
# File lib/state_machine_checker/transition.rb, line 35
def eql?(other)
  other == self
end
execute(instance) click to toggle source

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.

@param instance the instance to execute the transition on.

# 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
hash() click to toggle source
# File lib/state_machine_checker/transition.rb, line 39
def hash
  hash_attributes.map(&:hash).hash
end

Private Instance Methods

hash_attributes() click to toggle source
# File lib/state_machine_checker/transition.rb, line 45
def hash_attributes
  [:from, :to, :name]
end