获取最终state_machine状态列表

时间:2012-10-31 15:49:29

标签: ruby-on-rails ruby state-machine

StateMachine库to get the list of states中有一个方法:

ModelName.state_machines[:name_of_state].states.map &:name

ModelName.state_machines.states.map &:name

当包含状态的属性的名称是默认的“state”时。

然而,我想知道是否有办法找到最终的状态机,因为如果你用

绘制它们
rake state_machine:draw FILE=model.rb CLASS=ModelName

最终状态是双圈的。 我无法一眼就看到耙子任务的来源。

获得初始状态似乎很容易:

ModelName.state_machines[:name_of_state].states.select(&:initial).map(&:name)

更新

哦,傻瓜!它很简单:

ModelName.state_machines[:name_of_state].states.select(&:final?).map(&:name)

留待未来的Google员工使用!

0 个答案:

没有答案