From 9190230cb7a79dbe28d76c12c9d281a0811504c6 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Fri, 23 Mar 2012 14:41:11 +0000 Subject: Added find and find_all methods to AlertGroup class. --- lib/mauve/alert_group.rb | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'lib') 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 -- cgit v1.2.1