0

我可能会在 db 中保存一个时间表,repeats = schedule.to_hash或者repeats = schedule.to_yaml 然后从 db 中使用它schedule = repeats.from_hash

但我需要知道什么是规则。例如,如果每周重复一次,我如何将规则存储在 db 中,或者我如何从计划中知道规则?是否有一些方法,例如 .to_hash 和 .from_hash 用于规则?

4

1 回答 1

0

ASchedule可以有许多重复规则和异常规则。你可以通过schedule.recurrence_rules或得到它们schedule.exception_rules。此外,还可能存在重复时间异常时间。(有关这些规则的详细信息,请访问:https ://github.com/seejohnrun/ice_cube#quick-introductions )

因此,最好只将序列化存储Schedule在数据库中,而不是特定规则。

如果您愿意,类似to_hash和的方法to_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}
于 2013-05-08T08:56:53.617 回答