我有一个使用两个的模型
state machines
class MyModel < ActiveRecord::Base
state_machine :call_state, :initial => :pending do
event :start do
transition :pending => :started
end
event :restart do
transition :started => :pending
end
event :finish do
transition :started => :finished
end
end
state_machine :payment_state, :initial => :unpaid do
event :pay do
transition :unpaid => :paid
end
event :pay_back do
transition :paid => :paid_back
end
event :reject_payment do
transition :unpaid => :rejected
end
end
#tons of methods related with call_state
#tons of methods related with payment_state
end
我想把这个分开
ActiveRecord
三个模型:
-
要封装的模块/类
定义和方法
与相关的
call_state
-
要封装的模块/类
定义和方法
与相关的
payment_state
-
模块/类
与两者一起工作
。第三个模块/类可以有如下方法
def can_call?
xxx.paid? and yyy.can_start?
end
哪里
xxx
/
yyy
可能是
MyModel
实例或包装类中的方法。我不知道。。。
问题是:
最好的方法是什么?