<commit_before>class RecordTemplate < ActiveRecord::Base

  belongs_to :zone_template

  # General validations
  validates_presence_of :zone_template_id
  validates_associated :zone_template
  validates_presence_of :record_type

  before_save :update_soa_content
  before_validation :inherit_ttl
  after_initialize :update_convenience_accessors
  validate :validate_record_template

  # We need to cope with the SOA convenience
  SOA::SOA_FIELDS.each do |f|
    attr_accessor f
  end

  class << self
    def record_types
      Record.record_types
    end
  end

  # Hook into #reload
  def reload_with_content
    reload_without_content
    update_convenience_accessors
  end
  alias_method_chain :reload, :content

  # Convert this template record into a instance +record_type+ with the
  # attributes of the template copied over to the instance
  def build( domain_name = nil )
    # get the class of the record_type
    record_class = self.record_type.constantize

    # duplicate our own attributes, strip out the ones the destination doesn't
    # have (and the id as well)
    attrs = self.attributes.dup
    attrs.delete_if { |k,_| !record_class.columns.map( &:name ).include?( k ) }
    attrs.delete( :id )

    # parse each attribute, looking for %ZONE%
    unless domain_name.nil?
      attrs.keys.each do |k|
        attrs[k] = attrs[k].gsub( '%ZONE%', domain_name ) if attrs[k].is_a?( String )
      end<commit_msg>fixed bug in record template<commit_after>class RecordTemplate < ActiveRecord::Base

  belongs_to :zone_template

  # General validations
  validates_presence_of :zone_template_id
  validates_associated :zone_template
  validates_presence_of :record_type

  before_save :update_soa_content
  before_validation :inherit_ttl
  after_initialize :update_convenience_accessors
  validate :validate_record_template

  # We need to cope with the SOA convenience
  SOA::SOA_FIELDS.each do |f|
    attr_accessor f
  end

  class << self
    def record_types
      Record.record_types
    end
  end

  # Hook into #reload
  def reload_with_content
    reload_without_content
    update_convenience_accessors
  end
  alias_method_chain :reload, :content

  # Convert this template record into a instance +record_type+ with the
  # attributes of the template copied over to the instance
  def build( domain_name = nil )
    # get the class of the record_type
    record_class = self.record_type.constantize

    # duplicate our own attributes, strip out the ones the destination doesn't
    # have (and the id as well)
    attrs = self.attributes.dup.with_indifferent_access
    attrs.delete_if { |k,_| !record_class.columns.map( &:name ).include?( k ) }
    attrs.delete( :id )

    # parse each attribute, looking for %ZONE%
    unless domain_name.nil?
      attrs.keys.each do |k|
        attrs[k] = attrs[k].gsub( '%ZONE%', domain_name ) if attrs[k].is_a?( String )
      end
{'fraction_non_alphanumeric': 0.06873920552677029, 'fraction_numerical': 0.0, 'mean_word_length': 3.778877887788779, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '2735213', 'n_tokens_mistral': 906, 'n_tokens_neox': 889, 'n_words': 263}