diff options
author | Alex Young <alex@bytemark.co.uk> | 2015-04-21 09:40:00 +0100 |
---|---|---|
committer | Alex Young <alex@bytemark.co.uk> | 2015-04-21 09:40:00 +0100 |
commit | 010fb38dcad92061c3dd972776d5183ea0ed9250 (patch) | |
tree | 4662edaa7b266457b559d977453a64828394cd6f | |
parent | 552e87bd4bba2b30e1ae49f6ce997f46f5082465 (diff) |
Minor Alert extract method refactor
-rw-r--r-- | lib/mauve/alert.rb | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb index d27b5d4..5b86437 100644 --- a/lib/mauve/alert.rb +++ b/lib/mauve/alert.rb @@ -309,28 +309,22 @@ module Mauve Server.notification_push([self, at]) end - # Save an alert, creating a history and notifications, as needed. # + # Notification should happen if # - def save - # - # Notification should happen if - # - # * the alert has just been raised - # * the alert is raised and its acknowledged status has changed - # * the alert has just been cleared, and wasn't suppressed before the clear. - # - # - should_notify = ( - (self.raised? and self.was_cleared?) or - (self.raised? and self.was_acknowledged? != self.acknowledged?) or - (self.cleared? and self.was_raised? and !self.was_suppressed?) - ) + # * the alert has just been raised + # * the alert is raised and its acknowledged status has changed + # * the alert has just been cleared, and wasn't suppressed before the clear. + # + # + def should_notify? + (self.raised? and self.was_cleared?) or + (self.raised? and self.was_acknowledged? != self.acknowledged?) or + (self.cleared? and self.was_raised? and !self.was_suppressed?) + end - # - # Set the update type. - # - ut = if self.cleared? and !self.was_cleared? + def update_type_str + if self.cleared? and !self.was_cleared? "cleared" elsif self.raised? and !self.was_raised? "raised" @@ -341,7 +335,18 @@ module Mauve else nil end + end + + # Save an alert, creating a history and notifications, as needed. + # + # + def save + should_notify = self.should_notify? + # + # Set the update type. + # + ut = self.update_type_str history = nil unless ut.nil? |