2013-04-07 33 views
0

我可能会在分贝repeats = schedule.to_hash保存日程或repeats = schedule.to_yaml 然后用它从数据库schedule = repeats.from_hash红宝石宝石ice_cube。我怎样才能将重复规则存储在数据库中?

但我需要知道什么是规则。例如,如果它每周重复一次,我怎么能在db中存储规则,或者我怎么能从计划中知道规则?是否有一些像.to_hash和.from_hash这样的规则方法?

回答

0

A Schedule可能有许多重复出现异常规则。你可以通过做schedule.recurrence_rulesschedule.exception_rules。此外,还可以有重复次数例外时间以及。 (有关这些规则的详细信息,请访问:https://github.com/seejohnrun/ice_cube#quick-introductions

因此,将序列化的Schedule仅存储在数据库中而不是特定的规则是一种最佳做法。

如果你愿意的话,像to_hashto_yaml方法可在规则上也:

irb(main)> schedule.recurrence_rules.first.to_yaml 
=> "---\n:validations: {}\n:rule_type: IceCube::DailyRule\n:interval: 1\n" 

irb(main)> schedule.recurrence_rules.first.to_hash 
=> {:validations=>{}, :rule_type=>"IceCube::DailyRule", :interval=>1}