blob: de82674896a20e670ca901623d1d185f1f89c56f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
class Event < ApplicationRecord
include RruleHumanizer
belongs_to :node, optional: true
has_many :occurrences
validates :title, presence: true, unless: -> { node_id.present? }
validates :is_primary, uniqueness: { scope: :node_id,
message: "only one primary event per node allowed" },
if: -> { is_primary? && node_id.present? }
after_save :generate_occurences
def occurrences_in_range start_time, end_time
self.occurrences.where(
"start_time > ? AND end_time < ?",
start_time, end_time
)
end
def display_title
title.presence || node&.head&.title || "Untitled event"
end
private
def generate_occurences
Occurrence.generate self
end
end
|