Class: PrettyStateMachine::Transition

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(machine_class, name) ⇒ Transition

Returns a new instance of Transition.



5
6
7
8
9
# File 'lib/pretty_state_machine/transition.rb', line 5

def initialize(machine_class, name)
  @machine_class = machine_class
  @name = name
  @from_states = []
end

Instance Attribute Details

#to_stateObject (readonly)

Returns the value of attribute to_state.



3
4
5
# File 'lib/pretty_state_machine/transition.rb', line 3

def to_state
  @to_state
end

Instance Method Details

#from(*state_names) ⇒ Object



11
12
13
14
15
# File 'lib/pretty_state_machine/transition.rb', line 11

def from(*state_names)
  @from_states = state_names.flatten.compact.map { |state_name|
    @machine_class.state_from_name(state_name)
  }
end

#permitted_from?(state) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/pretty_state_machine/transition.rb', line 21

def permitted_from?(state)
  @from_states.include?(state)
end

#to(state_name) ⇒ Object



17
18
19
# File 'lib/pretty_state_machine/transition.rb', line 17

def to(state_name)
  @to_state = @machine_class.state_from_name(state_name)
end