Class: Schedule

Inherits:
ApplicationRecord show all
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 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 Schedulable

Schedulable::SIMPLE_FORM_OPTIONS

Instance Attribute Summary collapse

Belongs to collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#dateObject (readonly)



40
# File 'app/models/schedule.rb', line 40

validates :date, presence: true, if: -> { rule == 'singular' }

#ruleObject (readonly)



38
# File 'app/models/schedule.rb', line 38

validates :rule, presence: true

#timeTime? (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.

Returns:

  • (Time, nil)


52
# File 'app/models/schedule.rb', line 52

validates :time, presence: true

Class Method Details

.param_namesArray

Strong-parameter shape for a nested schedule form.

Returns:

  • (Array)


82
83
84
85
86
87
88
89
90
# File 'app/models/schedule.rb', line 82

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

#schedulableSchedulable



33
# File 'app/models/schedule.rb', line 33

belongs_to :schedulable, polymorphic: true

#to_icecubeIceCube::Schedule?

Returns the underlying recurrence schedule.

Returns:

  • (IceCube::Schedule, nil)

    the underlying recurrence schedule



65
66
67
# File 'app/models/schedule.rb', line 65

def to_icecube
  @schedule
end

#to_sString

Returns a localized, human-readable description of the schedule.

Returns:

  • (String)

    a localized, human-readable description of the schedule



70
71
72
73
74
75
76
77
# File 'app/models/schedule.rb', line 70

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