Sha256: 912eb43a6a1eb8c4151dbbfe5595252b815f1e166f9f00ce1f4f515382398711

Contents?: true

Size: 960 Bytes

Versions: 8

Compression:

Stored size: 960 Bytes

Contents

class Whoops::NotificationRule
  include Mongoid::Document
  
  field :email, :type => String
  field :matchers, :type => Array

  # This might come in handy in the future?
  # class << self.fields["matchers"]
  #   def set(object)
  #     object = object.split("\n").collect{ |m| m.strip } if object.is_a?(String)
  #     object
  #   end
  # end
  
  before_save :downcase_email
  
  def downcase_email
    self.email.downcase!
  end
  
  def matchers=(matchers)
    write_attribute(:matchers, matchers.split("\n").collect{ |m| m.strip })
  end
  
  def self.matches(event)
    
  end
  
  class Matcher
    attr_accessor :event_group
    
    # @param [ Whoops::EventGroup ]
    def initialize(event_group)
      self.event_group = event_group
    end
    
    def matching_emails
      matches.collect{|m| m.email}.uniq
    end
    
    def matches
      @matches ||= Whoops::NotificationRule.where(:matchers => /^#{event_group.service}/)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
whoops-0.2.4 app/models/whoops/notification_rule.rb
whoops-0.2.3 app/models/whoops/notification_rule.rb
whoops-0.2.2 app/models/whoops/notification_rule.rb
whoops-0.2.1 app/models/whoops/notification_rule.rb
whoops-0.2 app/models/whoops/notification_rule.rb
whoops-0.1.10 app/models/whoops/notification_rule.rb
whoops-0.1.9 app/models/whoops/notification_rule.rb
whoops-0.1.8 app/models/whoops/notification_rule.rb