Class: Event

Inherits:
ApplicationRecord show all
Defined in:
app/models/event.rb

Overview

== Schema Information

Table name: events
Database name: primary

id :integer not null, primary key
all_day :boolean default(FALSE), not null
description :string
end_time :datetime
event_type :enum
name :string
start_time :datetime
time_zone :string default("America/Chicago"), not null
created_at :datetime not null
updated_at :datetime not null
creator_id :integer
resource_id :integer

CRM marketing/PR event tracked on the calendar.

Has a date + start/end times interpreted in time_zone (default
"America/Chicago"). One or more authors are assigned via the
event_authors join table; creator_id is the audit record of who
first added the event and is set automatically from the current user.

Constant Summary collapse

DEFAULT_TIME_ZONE =

Returns:

  • (Object)
'America/Chicago'
TIME_ZONE_OPTIONS =

US-focused dropdown for the form, ordered west→east.

[
  ['Hawaii (HST)',        'Pacific/Honolulu'],
  ['Alaska (AKST/AKDT)',  'America/Anchorage'],
  ['Pacific (PST/PDT)',   'America/Los_Angeles'],
  ['Mountain (MST/MDT)',  'America/Denver'],
  ['Arizona (MST)',       'America/Phoenix'],
  ['Central (CST/CDT)',   'America/Chicago'],
  ['Eastern (EST/EDT)',   'America/New_York']
].freeze

Constants included from Models::Schedulable

Models::Schedulable::SIMPLE_FORM_OPTIONS

Instance Attribute Summary collapse

Has many collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#end_dateObject

End date for multi-day events. Defaults to the start date when blank, so a
single-day event only needs event_date.



88
89
90
# File 'app/models/event.rb', line 88

def end_date
  @end_date || end_time&.in_time_zone(effective_time_zone)&.to_date&.iso8601
end

#end_time_of_dayvoid

This method returns an undefined value.



100
101
102
# File 'app/models/event.rb', line 100

def end_time_of_day
  @end_time_of_day || end_time&.in_time_zone(effective_time_zone)&.strftime('%H:%M')
end

#event_dateObject

─── Virtual form inputs (start/end dates + wall-clock times) ──────────
The form lets the user pick a start date, an optional end date (for
multi-day events), and — unless the event is all-day — two wall-clock
times, all interpreted in time_zone. Combined into UTC start/end
timestamps in assemble_times_from_local_inputs so the DB is
timezone-agnostic. All-day events store start-of-day → end-of-day.



82
83
84
# File 'app/models/event.rb', line 82

def event_date
  @event_date || start_time&.in_time_zone(effective_time_zone)&.to_date&.iso8601
end

#event_typeEnum (readonly)

Returns:

  • (Enum)


66
# File 'app/models/event.rb', line 66

validates :event_type, presence: true

#nameString (readonly)

Returns:

  • (String)


64
# File 'app/models/event.rb', line 64

validates :name, presence: true

#start_time_of_dayvoid

This method returns an undefined value.



95
96
97
# File 'app/models/event.rb', line 95

def start_time_of_day
  @start_time_of_day || start_time&.in_time_zone(effective_time_zone)&.strftime('%H:%M')
end

#time_zoneString (readonly)

Returns:

  • (String)


68
69
# File 'app/models/event.rb', line 68

validates :time_zone, presence: true,
inclusion: { in: ->(_) { TIME_ZONE_OPTIONS.map(&:last) + [DEFAULT_TIME_ZONE] } }

Instance Method Details

#authorsActiveRecord::Relation<Author>

validate: false — Rails would otherwise run each Employee's own
validations whenever Event#valid? is called, which inherits any preexisting
data debt on legacy Employee/Party records (e.g. missing employee_record
rows) and surfaces as a phantom "Authors is invalid" error on the Event.

Returns:

  • (ActiveRecord::Relation<Author>)

See Also:



61
# File 'app/models/event.rb', line 61

has_many :authors, through: :event_authors, source: :employee, validate: false

#calendar_endvoid

This method returns an undefined value.



120
121
122
123
124
125
# File 'app/models/event.rb', line 120

def calendar_end
  return if end_time.blank?

  local = end_time.in_time_zone(effective_time_zone)
  all_day? ? (local.to_date + 1).iso8601 : local.strftime('%Y-%m-%dT%H:%M:%S')
end

#calendar_startObject

─── FullCalendar serialization ────────────────────────────────────────
All-day events use bare dates; FullCalendar treats the end date as
EXCLUSIVE, so we emit the day after the (inclusive) end date.



112
113
114
115
116
117
# File 'app/models/event.rb', line 112

def calendar_start
  return if start_time.blank?

  local = start_time.in_time_zone(effective_time_zone)
  all_day? ? local.to_date.iso8601 : local.strftime('%Y-%m-%dT%H:%M:%S')
end

#effective_time_zonevoid

This method returns an undefined value.



105
106
107
# File 'app/models/event.rb', line 105

def effective_time_zone
  time_zone.presence || DEFAULT_TIME_ZONE
end

#event_authorsActiveRecord::Relation<EventAuthor>

Returns:



56
# File 'app/models/event.rb', line 56

has_many :event_authors, dependent: :destroy, inverse_of: :event