summaryrefslogtreecommitdiff
path: root/app/models/broadcast_message.rb
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-12-31 17:07:11 -0500
committerRobert Speicher <rspeicher@gmail.com>2016-01-13 11:34:58 -0500
commitdf496fcaf08b085816a45d31d02f1ea230454b63 (patch)
tree9d7c23c6c33cc96f4e216db234a8ac63bb8e3581 /app/models/broadcast_message.rb
parent5a1706791e46fd69a67fcdebfc384a702b00a7ff (diff)
downloadgitlab-ce-df496fcaf08b085816a45d31d02f1ea230454b63.tar.gz
Update BroadcastMessage model
- Adds default values for `color` and `font` attributes - Adds `active?`, `started?`, `ended?`, and 'status' methods
Diffstat (limited to 'app/models/broadcast_message.rb')
-rw-r--r--app/models/broadcast_message.rb27
1 files changed, 26 insertions, 1 deletions
diff --git a/app/models/broadcast_message.rb b/app/models/broadcast_message.rb
index da0d8a2d65f..188545f9ae5 100644
--- a/app/models/broadcast_message.rb
+++ b/app/models/broadcast_message.rb
@@ -22,7 +22,32 @@ class BroadcastMessage < ActiveRecord::Base
validates :color, allow_blank: true, color: true
validates :font, allow_blank: true, color: true
+ default_value_for :color, '#E75E40'
+ default_value_for :font, '#FFFFFF'
+
def self.current
- where("ends_at > :now AND starts_at < :now", now: Time.zone.now).last
+ where("ends_at > :now AND starts_at <= :now", now: Time.zone.now).last
+ end
+
+ def active?
+ started? && !ended?
+ end
+
+ def started?
+ Time.zone.now >= starts_at
+ end
+
+ def ended?
+ ends_at < Time.zone.now
+ end
+
+ def status
+ if active?
+ 'Active'
+ elsif ended?
+ 'Expired'
+ else
+ 'Pending'
+ end
end
end