<commit_before># encoding: utf-8

module Mongoid

  module Identifiable

    extend ActiveSupport::Concern

    included do

      class_attribute :identity_field

      has_many :handles, as: :identifiable

      class << self
        def identity(value, allowed_changes: 1)

          self.identity_field = value

          belongs_to :handle,  foreign_key: identity_field,  primary_key: :name,  :validate => false,   autosave: true

          attr_accessible identity_field

          field "#{identity_field}",                 type: String
          field "force_#{identity_field}_change",    type: Boolean,  default: false
          field "#{identity_field}_changed_at",      type: DateTime
          field "#{identity_field}_changes_allowed", type: Integer,  default: allowed_changes

          index({ identity_field => 1 }, { unique: 1 })

          validates identity_field, presence: true, variety: true, :change => {
            :allow => -> { self.send("#{identity_field}_changes_allowed") >= 1 },
            :message => "has been changed too many times"
          }

          validate :identity_validity

          before_validation :generate_identity,         :unless => "#{identity_field}? and handle?"
          after_validation  :decrease_identity_changes, :if => "#{identity_field}_changed?"

          define_method "#{identity_field}=" do |value|
            if value.present?
              self.handle = Handle.build(self, value)
              self.handle.identifiable = self
<commit_msg>Changed some semantics.<commit_after># encoding: utf-8

module Mongoid

  module Identifiable

    extend ActiveSupport::Concern

    included do

      class_attribute :identity_field

      has_many :handles, as: :identifiable

      class << self
        def identity(value, allowed_changes: 1)

          self.identity_field = value

          belongs_to :handle,  foreign_key: identity_field,  primary_key: :name,  :validate => false,   autosave: true

          attr_accessible identity_field

          field "#{identity_field}",                 type: String
          field "force_#{identity_field}_change",    type: Boolean,  default: false
          field "#{identity_field}_changed_at",      type: DateTime
          field "#{identity_field}_changes_allowed", type: Integer,  default: allowed_changes

          index({ identity_field => 1 }, { unique: 1 })

          validates identity_field, presence: true, variety: true, :change => {
            :allow => -> { self.send("#{identity_field}_changes_allowed") >= 1 },
            :message => "has been changed too many times"
          }

          validate :identity_validity

          before_validation :generate_identity,         :unless => "#{identity_field}? && handle?"
          after_validation  :decrease_identity_changes, :if => "#{identity_field}_changed?"

          define_method "#{identity_field}=" do |value|
            if value.present?
              self.handle = Handle.build(self, value)
              self.handle.identifiable = self

{'fraction_non_alphanumeric': 0.10062685582316068, 'fraction_numerical': 0.003299241174529858, 'mean_word_length': 2.5337995337995336, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '2253632', 'n_tokens_mistral': 821, 'n_tokens_neox': 774, 'n_words': 205}