17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/mongoid_recurring/has_recurring_fields.rb', line 17
def has_recurring_fields options={}
@@schedule_duration = options[:schedule_duration] if options[:schedule_duration].present?
field :dtstart, type: DateTime
field :dtend, type: DateTime
field :all_day, type: Mongoid::Boolean, default: false
field :schedule, type: MongoidIceCubeExtension::Schedule
field :schedule_dtend, type: DateTime
embeds_many :occurrences, class_name: 'MongoidRecurring::Occurrence', order: :dtstart.asc
validates :dtstart, presence: true
before_save :expand_schedule_to_occurrences
scope :for_datetime_range, -> (dtstart, dtend) {
where({ occurrences: { "$elemMatch" => Occurrence.for_datetime_range(dtstart, dtend).selector } })
}
scope :from_datetime, -> (dtstart) {
where( occurrences: { "$elemMatch" => Occurrence.from_datetime(dtstart).selector } )
}
scope :to_datetime, -> (dtend) {
where( occurrences: { "$elemMatch" => Occurrence.to_datetime(dtend).selector } )
}
end
|