17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# 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: Boolean, default: false
field :schedule, type: MongoidIceCubeExtension::Schedule
field :schedule_dtend, type: DateTime
embeds_many :occurrences, class_name: 'MongoidRecurring::Occurence', order: :dtstart.asc
validates :dtstart, presence: true
before_save :expand_schedule_to_occurrences
scope :for_datetime_range, -> (dtstart, dtend) {
where( occurrences: { "$elemMatch" => { :dtstart.gte => dtstart.to_datetime, :dtend.lte => dtend.to_datetime } } )
}
end
|