Class: Schedule
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Schedule
- Defined in:
- app/models/schedule.rb
Overview
== Schema Information
Table name: schedules
Database name: primary
id :integer not null, primary key
count :integer
date :date
day :text
day_of_week :text
interval :string
rule :string
schedulable_type :string
time :time
until :datetime
created_at :datetime
updated_at :datetime
schedulable_id :integer
A recurrence rule attached to a schedulable record (see Models::Schedulable).
Vendored from the schedulable gem's Schedulable::Model::Schedule base
class. rule selects the recurrence kind (singular, daily, weekly,
monthly); the matching IceCube::Schedule is rebuilt on every load and
save, and unknown method calls delegate to it.
Constant Summary
Constants included from Models::Schedulable
Models::Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Validates a date is present for one-off schedules.
-
#rule ⇒ Object
readonly
Validates a recurrence rule is present.
-
#time ⇒ Time?
readonly
Normalizes the AR
timevalue to a coreTime.
Belongs to collapse
-
#schedulable ⇒ Schedulable
Record this schedule belongs to (employee, store, etc.).
Class Method Summary collapse
-
.param_names ⇒ Array
Strong-parameter shape for a nested schedule form.
Instance Method Summary collapse
-
#to_icecube ⇒ IceCube::Schedule?
The underlying recurrence schedule.
-
#to_s ⇒ String
A localized, human-readable description of the schedule.
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#date ⇒ Object (readonly)
Validates a date is present for one-off schedules.
Validations (if => -> { rule == 'singular' } ):
44 |
# File 'app/models/schedule.rb', line 44 validates :date, presence: true, if: -> { rule == 'singular' } |
#rule ⇒ Object (readonly)
Validates a recurrence rule is present.
Validations:
40 |
# File 'app/models/schedule.rb', line 40 validates :rule, presence: true |
#time ⇒ Time? (readonly)
Normalizes the AR time value to a core Time.
ActiveRecord maps time columns to ActiveSupport::TimeWithZone;
callers (and the recurrence builder) expect a plain Time.
42 |
# File 'app/models/schedule.rb', line 42 validates :time, presence: true |
Class Method Details
.param_names ⇒ Array
Strong-parameter shape for a nested schedule form.
86 87 88 89 90 91 92 93 94 |
# File 'app/models/schedule.rb', line 86 def self.param_names [ :id, :date, :time, :time_end, :rule, :until, :count, :interval, { day: [], day_of_week: { monday: [], tuesday: [], wednesday: [], thursday: [], friday: [], saturday: [], sunday: [] } } ] end |
Instance Method Details
#schedulable ⇒ Schedulable
Record this schedule belongs to (employee, store, etc.).
34 |
# File 'app/models/schedule.rb', line 34 belongs_to :schedulable, polymorphic: true |
#to_icecube ⇒ IceCube::Schedule?
Returns the underlying recurrence schedule.
69 70 71 |
# File 'app/models/schedule.rb', line 69 def to_icecube @schedule end |
#to_s ⇒ String
Returns a localized, human-readable description of the schedule.
74 75 76 77 78 79 80 81 |
# File 'app/models/schedule.rb', line 74 def to_s if rule == 'singular' datetime = date.to_datetime + time.seconds_since_midnight.seconds I18n.localize(datetime, format: :long) else to_icecube.to_s end end |