mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
Add aasm_events_for_state and aasm_events_for_current_state [Joao Paulo Lins]
This commit is contained in:
parent
bb5f7e00a4
commit
32156165d4
3 changed files with 15 additions and 0 deletions
|
@ -1,3 +1,5 @@
|
|||
* Add #aasm_events_for_state and #aasm_events_for_current_state [Joao Paulo Lins]
|
||||
|
||||
* Ensure that a state is written for a new record even if aasm_current_state or
|
||||
{state}= are never called.
|
||||
|
||||
|
|
|
@ -69,6 +69,15 @@ module AASM
|
|||
self.class.aasm_initial_state
|
||||
end
|
||||
|
||||
def aasm_events_for_current_state
|
||||
aasm_events_for_state(aasm_current_state)
|
||||
end
|
||||
|
||||
def aasm_events_for_state(state)
|
||||
events = self.class.aasm_events.values.select {|event| event.transitions_from_state?(state) }
|
||||
events.map {|event| event.name}
|
||||
end
|
||||
|
||||
private
|
||||
def aasm_current_state=(state)
|
||||
@aasm_current_state = state
|
||||
|
|
|
@ -25,6 +25,10 @@ module AASM
|
|||
next_state
|
||||
end
|
||||
|
||||
def transitions_from_state?(state)
|
||||
@transitions.any? { |t| t.from == state }
|
||||
end
|
||||
|
||||
private
|
||||
def transitions(trans_opts)
|
||||
Array(trans_opts[:from]).each do |s|
|
||||
|
|
Loading…
Reference in a new issue