Class: SchedulerProfile
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- SchedulerProfile
- Extended by:
- FriendlyId
- Defined in:
- app/models/scheduler_profile.rb
Overview
== Schema Information
Table name: scheduler_profiles
Database name: primary
id :bigint not null, primary key
buffer_after_lunch_minutes :integer default(0), not null
buffer_before_lunch_minutes :integer default(0), not null
buffer_end_of_day_minutes :integer default(0), not null
buffer_start_of_day_minutes :integer default(0), not null
max_bookings_per_day :jsonb not null
scheduler_enabled :boolean default(FALSE), not null
slug :string not null
timezone :string default("America/Chicago"), not null
created_at :datetime not null
updated_at :datetime not null
employee_id :bigint not null
Indexes
index_scheduler_profiles_on_employee_id (employee_id) UNIQUE
index_scheduler_profiles_on_scheduler_enabled (scheduler_enabled)
index_scheduler_profiles_on_slug (slug) UNIQUE
Foreign Keys
fk_rails_... (employee_id => parties.id) ON DELETE => cascade
Constant Summary collapse
- BUFFER_OPTIONS =
Available buffer options.
[0, 15, 30, 45, 60, 90, 120].freeze
- MAX_BOOKINGS_OPTIONS =
Maximum bookings options.
[nil, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10].freeze
Constants included from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
- #buffer_after_lunch_minutes ⇒ Object readonly
- #buffer_before_lunch_minutes ⇒ Object readonly
- #buffer_end_of_day_minutes ⇒ Object readonly
- #buffer_start_of_day_minutes ⇒ Object readonly
- #employee_id ⇒ Object readonly
- #slug ⇒ Object readonly
Belongs to collapse
Instance Method Summary collapse
- #max_bookings_for_wday(wday) ⇒ Object
- #max_bookings_per_day=(hash) ⇒ Object
- #should_generate_new_friendly_id? ⇒ Boolean
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#buffer_after_lunch_minutes ⇒ Object (readonly)
41 42 43 |
# File 'app/models/scheduler_profile.rb', line 41 validates :buffer_start_of_day_minutes, :buffer_end_of_day_minutes, :buffer_before_lunch_minutes, :buffer_after_lunch_minutes, numericality: { only_integer: true, greater_than_or_equal_to: 0 } |
#buffer_before_lunch_minutes ⇒ Object (readonly)
41 42 43 |
# File 'app/models/scheduler_profile.rb', line 41 validates :buffer_start_of_day_minutes, :buffer_end_of_day_minutes, :buffer_before_lunch_minutes, :buffer_after_lunch_minutes, numericality: { only_integer: true, greater_than_or_equal_to: 0 } |
#buffer_end_of_day_minutes ⇒ Object (readonly)
41 42 43 |
# File 'app/models/scheduler_profile.rb', line 41 validates :buffer_start_of_day_minutes, :buffer_end_of_day_minutes, :buffer_before_lunch_minutes, :buffer_after_lunch_minutes, numericality: { only_integer: true, greater_than_or_equal_to: 0 } |
#buffer_start_of_day_minutes ⇒ Object (readonly)
41 42 43 |
# File 'app/models/scheduler_profile.rb', line 41 validates :buffer_start_of_day_minutes, :buffer_end_of_day_minutes, :buffer_before_lunch_minutes, :buffer_after_lunch_minutes, numericality: { only_integer: true, greater_than_or_equal_to: 0 } |
#employee_id ⇒ Object (readonly)
38 |
# File 'app/models/scheduler_profile.rb', line 38 validates :employee_id, uniqueness: true |
#slug ⇒ Object (readonly)
39 40 |
# File 'app/models/scheduler_profile.rb', line 39 validates :slug, presence: true, uniqueness: true, format: { with: /\A[a-z0-9]+(?:-[a-z0-9]+)*\z/, message: 'only lowercase letters, numbers, and hyphens' } |
Instance Method Details
#max_bookings_for_wday(wday) ⇒ Object
52 53 54 55 56 57 |
# File 'app/models/scheduler_profile.rb', line 52 def max_bookings_for_wday(wday) return nil unless has_attribute?(:max_bookings_per_day) value = max_bookings_per_day[wday.to_s] value.presence&.to_i end |
#max_bookings_per_day=(hash) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'app/models/scheduler_profile.rb', line 59 def max_bookings_per_day=(hash) return unless has_attribute?(:max_bookings_per_day) cleaned = hash.each_with_object({}) do |(k, v), h| h[k.to_s] = v.presence&.to_i end super(cleaned) end |
#should_generate_new_friendly_id? ⇒ Boolean
68 69 70 |
# File 'app/models/scheduler_profile.rb', line 68 def should_generate_new_friendly_id? slug.blank? end |