app/models/message.rb in hackathon_manager-0.7.1 vs app/models/message.rb in hackathon_manager-0.8.0

- old
+ new

@@ -4,10 +4,12 @@ strip_attributes POSSIBLE_TEMPLATES = ["default"].freeze + POSSIBLE_TYPES = ["bulk", "automated"].freeze + POSSIBLE_SIMPLE_RECIPIENTS = { "all" => "Everyone", "incomplete" => "Incomplete Applications", "complete" => "Complete Applications", "accepted" => "Accepted Applications", @@ -32,10 +34,11 @@ }.freeze serialize :recipients, Array validates_inclusion_of :template, in: POSSIBLE_TEMPLATES + validates_inclusion_of :type, in: POSSIBLE_TYPES def recipients=(values) values.present? ? super(values.reject(&:blank?)) : super(values) end @@ -50,10 +53,18 @@ end end labels end + def bulk? + type == "bulk" + end + + def automated? + type == "automated" + end + def delivered? delivered_at.present? end def started? @@ -63,18 +74,19 @@ def queued? queued_at.present? end def status + return "automated" if automated? return "delivered" if delivered? return "started" if started? return "queued" if queued? "drafted" end def can_edit? - status == "drafted" || trigger.present? + automated? || status == "drafted" end def can_queue? status == "drafted" && recipients_list.present? end @@ -124,7 +136,19 @@ end def self.queue_for_trigger(trigger, user_id) messages_to_queue = Message.where(trigger: trigger) messages_to_queue.map { |message| Mailer.delay.bulk_message_email(message.id, user_id) } + end + + def self.bulk + where(type: 'bulk') + end + + def self.automated + where(type: 'automated') + end + + def self.inheritance_column + "class_type" end end