diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-03-23 14:41:11 +0000 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-03-23 14:41:11 +0000 |
commit | 9190230cb7a79dbe28d76c12c9d281a0811504c6 (patch) | |
tree | b2c85350ed26bb79a3e6c0a30b48a76d10558593 | |
parent | e8c7d1742ada73ce487b5db49c682f0cb3157f4e (diff) |
Added find and find_all methods to AlertGroup class.
-rw-r--r-- | lib/mauve/alert_group.rb | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/mauve/alert_group.rb b/lib/mauve/alert_group.rb index 7ea7ffb..2f234ec 100644 --- a/lib/mauve/alert_group.rb +++ b/lib/mauve/alert_group.rb @@ -26,7 +26,7 @@ module Mauve # # @return [Array] AlertGroups that match def matches(alert) - grps = all.select { |alert_group| alert_group.includes?(alert) } + grps = find_all { |alert_group| alert_group.includes?(alert) } # # Make sure we always match the last (and therefore default) group. @@ -36,6 +36,28 @@ module Mauve grps end + # + # + # + def find_all(&block) + return all unless block_given? + + all.find_all do |alert_group| + yield(alert_group) + end + end + + # + # + # + def find(&block) + return nil unless block_given? + + all.find do |alert_group| + yield(alert_group) + end + end + # @return [Log4r::Logger] def logger Log4r::Logger.new self.to_s |