<commit_before>module Houston
  module Alerts
    class Alert < ActiveRecord::Base
      attr_accessor :updated_by
      
      self.table_name = "alerts"
      self.inheritance_column = nil
      
      belongs_to :project
      belongs_to :checked_out_by, class_name: "User"
      
      default_value_for :opened_at do; Time.now; end
      
      default_scope { where(destroyed_at: nil).order(:deadline) }
      
      validates :type, :key, :summary, :url, :opened_at, presence: true
      validates :priority, presence: true, inclusion: {:in => %w{high urgent}}
      
      before_save :update_checked_out_by, :if => :checked_out_by_email_changed?
      before_save :update_project, :if => :project_slug_changed?
      before_save :update_deadline, :if => :opened_at_or_priority_changed?
      
      after_create do
        Houston.observer.fire "alert:create", self
        Houston.observer.fire "alert:#{type}:create", self
      end
      
      after_update do
        if checked_out_by_id_changed?
          Houston.observer.fire "alert:assign", self
          Houston.observer.fire "alert:#{type}:assign", self
        end
      end
      
      
      
      class << self
        def open
          where(closed_at: nil)
        end
        
        def closed(options={})
          if options.key?(:after)
            where(arel_table[:closed_at].gteq(options[:after]))
          else
            where(arel_table[:closed_at].not_eq(nil))
          end
        end
        
        def closed_on(date)
          where(closed_at: date.to_time.beginning_of_day..date.to_time.end_of_day)
        end
        
        def checked_out
          where(arel_table[:checked_out_by_id].not_eq(nil))
        end
        
        def checked_out_by(user)
          where(checked_out_by_id: user.id)
        end
        
        def due_before(time)
          where(arel_table[:deadline].lteq(time))
        end
        
        def closed_or_due_during(range)
          range = range.to_range if range.respond_to?(:to_range)
          where(
            arel_table[:deadline].in(range).or(
            arel_table[:closed_at].in(range)
          ))
        end
        
        def without(*keys)
          where(arel_table[:key].not_in(keys.flatten))
        end
        
        def destroyed<commit_msg>[skip] Added a scope to Alert (1m)<commit_after>module Houston
  module Alerts
    class Alert < ActiveRecord::Base
      attr_accessor :updated_by
      
      self.table_name = "alerts"
      self.inheritance_column = nil
      
      belongs_to :project
      belongs_to :checked_out_by, class_name: "User"
      
      default_value_for :opened_at do; Time.now; end
      
      default_scope { where(destroyed_at: nil).order(:deadline) }
      
      validates :type, :key, :summary, :url, :opened_at, presence: true
      validates :priority, presence: true, inclusion: {:in => %w{high urgent}}
      
      before_save :update_checked_out_by, :if => :checked_out_by_email_changed?
      before_save :update_project, :if => :project_slug_changed?
      before_save :update_deadline, :if => :opened_at_or_priority_changed?
      
      after_create do
        Houston.observer.fire "alert:create", self
        Houston.observer.fire "alert:#{type}:create", self
      end
      
      after_update do
        if checked_out_by_id_changed?
          Houston.observer.fire "alert:assign", self
          Houston.observer.fire "alert:#{type}:assign", self
        end
      end
      
      
      
      class << self
        def open
          where(closed_at: nil)
        end
        
        def closed(options={})
          if options.key?(:after)
            where(arel_table[:closed_at].gteq(options[:after]))
          else
            where(arel_table[:closed_at].not_eq(nil))
          end
        end
        
        def closed_on_time
          closed.where(arel_table[:closed_at].lteq(arel_table[:deadline]))
        end
        
        def closed_on(date)
          where(closed_at: date.to_time.beginning_of_day..date.to_time.end_of_day)
        end
        
        def checked_out
          where(arel_table[:checked_out_by_id].not_eq(nil))
        end
        
        def checked_out_by(user)
          where(checked_out_by_id: user.id)
        end
        
        def due_before(time)
          where(arel_table[:deadline].lteq(time))
        end
        
        def closed_or_due_during(range)
          range = range.to_range if range.respond_to?(:to_range)
          where(
            arel_table[:deadline].in(range).or(
            arel_table[:closed_at].in(range)
          ))
        end
        
        def without(*keys)
          where(arel_table[:key].not_in(keys.flatten))
        end
        
        def destroyed
{'fraction_non_alphanumeric': 0.09441879983214435, 'fraction_numerical': 0.000209819555182543, 'mean_word_length': 1.9608695652173913, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4991647', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1449, 'n_words': 261}