lib/flapjack/data/notification_rule.rb in flapjack-0.8.4 vs lib/flapjack/data/notification_rule.rb in flapjack-0.8.5
- old
+ new
@@ -36,10 +36,14 @@
# replacing save! etc
def self.add(rule_data, options = {})
raise "Redis connection not set" unless redis = options[:redis]
- rule_id = SecureRandom.uuid
+ if rule_data[:id] && self.find_by_id(rule_data[:id], :redis => redis)
+ errors = ["a notification rule already exists with id '#{rule_data[:id]}'"]
+ return errors
+ end
+ rule_id = rule_data[:id] || SecureRandom.uuid
errors = self.add_or_update(rule_data.merge(:id => rule_id), options)
return errors unless errors.nil? || errors.empty?
self.find_by_id(rule_id, :redis => redis)
end