Module: LiteralEnums::Transitions

Included in:
Enum
Defined in:
lib/literal_enums/transitions.rb

Instance Method Summary collapse

Instance Method Details

#>>(new_state) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/literal_enums/transitions.rb', line 3

def >>(new_state)
  return self if new_state == self

  if transitions_to?(new_state)
    new_state
  else
    raise TransitionError,
      "You can't transition from #{self.name} to #{new_state.name}."
  end
end

#transitions_to?(new_state) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
# File 'lib/literal_enums/transitions.rb', line 14

def transitions_to?(new_state)
  possible_states = transitions_to

  case possible_states
  when Enum
    possible_states == new_state
  when Array
    possible_states.include?(new_state)
  end
end