<commit_before>class App
  include Mongoid::Document
  include Mongoid::Timestamps

  field :name, :type => String
  field :api_key
  field :github_url
  field :resolve_errs_on_deploy, :type => Boolean, :default => false
  field :notify_all_users, :type => Boolean, :default => false
  field :notify_on_errs, :type => Boolean, :default => true
  field :notify_on_deploys, :type => Boolean, :default => true
  field :email_at_notices, :type => Array, :default => Errbit::Config.email_at_notices

  # Some legacy apps may have sting as key instead of BSON::ObjectID
  identity :type => String
  # There seems to be a Mongoid bug making it impossible to use String identity with references_many feature:
  # https://github.com/mongoid/mongoid/issues/703
  # Using 32 character string as a workaround.
  before_create do |r|
    r.id = ActiveSupport::SecureRandom.hex
  end

  embeds_many :watchers
  embeds_many :deploys
  embeds_one :issue_tracker
  has_many :errs, :inverse_of => :app, :dependent => :destroy

  before_validation :generate_api_key, :on => :create
  before_save :normalize_github_url

  validates_presence_of :name, :api_key
  validates_uniqueness_of :name, :allow_blank => true
  validates_uniqueness_of :api_key, :allow_blank => true
  validates_associated :watchers
  validate :check_issue_tracker

  accepts_nested_attributes_for :watchers, :allow_destroy => true,
    :reject_if => proc { |attrs| attrs[:user_id].blank? && attrs[:email].blank? }
  accepts_nested_attributes_for :issue_tracker, :allow_destroy => true,
    :reject_if => proc { |attrs| !%w(none lighthouseapp redmine pivotal fogbugz mingle).include?(attrs[:issue_tracker_type]) }

  # Mongoid Bug: find(id) on association proxies returns an Enumerator
  def self.find_by_id!(app_id)
    where(:_id => app_id).first || raise(Mongoid::Errors::DocumentNotFound.new(self,app_id))
  end

  def self.find_by_api_key!(key)
    where(:api_key => key).first || raise(Mongoid::Errors::DocumentNotFound.new(self,key))
  end

  def last_deploy_at
    deploys.last && deploys.last.created_at
  end

  # Legacy apps don't have notify_on_errs and notify_on_deploys params
  def notify_on_errs
    !(self[:notify_on_errs] == false)
  end
  alias :notify_on_errs? :notify_on_errs

  def notify_on_deploys
    !(self[:notify_on_deploys] == false)
  end
  alias :notify_on_deploys? :notify_on_deploys

  def github_url?
    self.github_url.present?
  end
<commit_msg>Simpler App.find_by_id.<commit_after>class App
  include Mongoid::Document
  include Mongoid::Timestamps

  field :name, :type => String
  field :api_key
  field :github_url
  field :resolve_errs_on_deploy, :type => Boolean, :default => false
  field :notify_all_users, :type => Boolean, :default => false
  field :notify_on_errs, :type => Boolean, :default => true
  field :notify_on_deploys, :type => Boolean, :default => true
  field :email_at_notices, :type => Array, :default => Errbit::Config.email_at_notices

  # Some legacy apps may have sting as key instead of BSON::ObjectID
  identity :type => String
  # There seems to be a Mongoid bug making it impossible to use String identity with references_many feature:
  # https://github.com/mongoid/mongoid/issues/703
  # Using 32 character string as a workaround.
  before_create do |r|
    r.id = ActiveSupport::SecureRandom.hex
  end

  embeds_many :watchers
  embeds_many :deploys
  embeds_one :issue_tracker
  has_many :errs, :inverse_of => :app, :dependent => :destroy

  before_validation :generate_api_key, :on => :create
  before_save :normalize_github_url

  validates_presence_of :name, :api_key
  validates_uniqueness_of :name, :allow_blank => true
  validates_uniqueness_of :api_key, :allow_blank => true
  validates_associated :watchers
  validate :check_issue_tracker

  accepts_nested_attributes_for :watchers, :allow_destroy => true,
    :reject_if => proc { |attrs| attrs[:user_id].blank? && attrs[:email].blank? }
  accepts_nested_attributes_for :issue_tracker, :allow_destroy => true,
    :reject_if => proc { |attrs| !%w(none lighthouseapp redmine pivotal fogbugz mingle).include?(attrs[:issue_tracker_type]) }

  def self.find_by_id!(app_id)
    find app_id
  end

  def self.find_by_api_key!(key)
    where(:api_key => key).first || raise(Mongoid::Errors::DocumentNotFound.new(self,key))
  end

  def last_deploy_at
    deploys.last && deploys.last.created_at
  end

  # Legacy apps don't have notify_on_errs and notify_on_deploys params
  def notify_on_errs
    !(self[:notify_on_errs] == false)
  end
  alias :notify_on_errs? :notify_on_errs

  def notify_on_deploys
    !(self[:notify_on_deploys] == false)
  end
  alias :notify_on_deploys? :notify_on_deploys

  def github_url?
    self.github_url.present?
  end

{'fraction_non_alphanumeric': 0.10321489001692047, 'fraction_numerical': 0.0021150592216582064, 'mean_word_length': 4.96343001261034, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 48, 'https://': 2, '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': '461043', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1602, 'n_words': 387}