Ruby Gem ice_cube。如何在数据库中存储重复规则?

时间:2013-04-07 08:32:16

标签: ruby-on-rails rubygems ice-cube

我可能会在db repeats = schedule.to_hashrepeats = schedule.to_yaml中保存计划 然后从db schedule = repeats.from_hash

中使用它

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

1 个答案:

答案 0 :(得分:0)

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}