<commit_before>class Person
  include MongoMapper::Document
  include ROXML

  xml_accessor :_id
  xml_accessor :email
  xml_accessor :url
  xml_accessor :profile, :as => Profile
  
  
  key :email, String
  key :url, String
  key :active, Boolean, :default => false
  key :key_fingerprint, String

  one :profile, :class_name => 'Profile', :foreign_key => :person_id
  many :posts, :class_name => 'Post', :foreign_key => :person_id

  timestamps!

  before_validation :clean_url
  validates_presence_of :email, :url
  validates_format_of :url, :with =>
     /^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix
  
  validates_true_for :url, :logic => lambda { self.url_unique?}

  after_destroy :remove_all_traces

  scope :friends,  where(:_type => "Person", :active => true)


 
  def real_name
    "#{profile.first_name.to_s} #{profile.last_name.to_s}"
  end

  def key
    GPGME::Ctx.new.get_key key_fingerprint
  end


  protected
  
  def url_unique?
    same_url = Person.first(:url => self.url)
    return same_url.nil? || same_url.id == self.id
  end

  def clean_url
    self.url ||= "http://localhost:3000/" if self.class == User
    if self.url
      self.url = 'http://' + self.url unless self.url.match('http://' || 'https://')
      self.url = self.url + '/' if self.url[-1,1] != '/'
    end
  end

  private

  def remove_all_traces
    self.posts.delete_all
    Comment.delete_all(:person_id => self.id)<commit_msg>RS, DG; person destruction no longer deletes comments<commit_after>class Person
  include MongoMapper::Document
  include ROXML

  xml_accessor :_id
  xml_accessor :email
  xml_accessor :url
  xml_accessor :profile, :as => Profile
  
  
  key :email, String
  key :url, String
  key :active, Boolean, :default => false
  key :key_fingerprint, String

  one :profile, :class_name => 'Profile', :foreign_key => :person_id
  many :posts, :class_name => 'Post', :foreign_key => :person_id

  timestamps!

  before_validation :clean_url
  validates_presence_of :email, :url
  validates_format_of :url, :with =>
     /^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix
  
  validates_true_for :url, :logic => lambda { self.url_unique?}

  after_destroy :remove_all_traces

  scope :friends,  where(:_type => "Person", :active => true)


 
  def real_name
    "#{profile.first_name.to_s} #{profile.last_name.to_s}"
  end

  def key
    GPGME::Ctx.new.get_key key_fingerprint
  end


  protected
  
  def url_unique?
    same_url = Person.first(:url => self.url)
    return same_url.nil? || same_url.id == self.id
  end

  def clean_url
    self.url ||= "http://localhost:3000/" if self.class == User
    if self.url
      self.url = 'http://' + self.url unless self.url.match('http://' || 'https://')
      self.url = self.url + '/' if self.url[-1,1] != '/'
    end
  end

  private

  def remove_all_traces
    self.posts.delete_all
{'fraction_non_alphanumeric': 0.1637047163362953, 'fraction_numerical': 0.01161995898838004, 'mean_word_length': 3.323485967503693, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '1959632', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1085, 'n_words': 230}