Class: BroadcastMessage

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Sortable
Defined in:
app/models/broadcast_message.rb

Overview

Schema Information

Table name: broadcast_messages

id         :integer          not null, primary key
message    :text             not null
starts_at  :datetime
ends_at    :datetime
created_at :datetime
updated_at :datetime
color      :string
font       :string

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.currentObject


28
29
30
31
32
# File 'app/models/broadcast_message.rb', line 28

def self.current
  Rails.cache.fetch("broadcast_message_current", expires_in: 1.minute) do
    where("ends_at > :now AND starts_at <= :now", now: Time.zone.now).last
  end
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)

34
35
36
# File 'app/models/broadcast_message.rb', line 34

def active?
  started? && !ended?
end

#ended?Boolean

Returns:

  • (Boolean)

42
43
44
# File 'app/models/broadcast_message.rb', line 42

def ended?
  ends_at < Time.zone.now
end

#started?Boolean

Returns:

  • (Boolean)

38
39
40
# File 'app/models/broadcast_message.rb', line 38

def started?
  Time.zone.now >= starts_at
end