<commit_before>class SiteForm
  include ActiveModel::Model

  attr_accessor(
    :id,
    :external_id,
    :name,
    :domain,
    :configuration_data,
    :location_name,
    :location_type,
    :institution_url,
    :institution_type,
    :institution_email,
    :institution_address,
    :institution_document_number,
    :head_markup,
    :foot_markup,
    :created_at,
    :updated_at
  )

  validates :name, presence: true
  validates :location_name, presence: true
  validates :domain, presence: true, domain: true

  delegate :persisted?, to: :site

  def save
    save_site if valid?
  end

  def site
    @site ||= Site.find_by(id: id).presence || build_site
  end

  private

  def build_site
    Site.new
  end

  def save_site
    @site = site.tap do |site_attributes|
      site_attributes.name                        = name
      site_attributes.domain                      = domain
      site_attributes.configuration_data          = configuration_data
      site_attributes.location_name               = location_name
      site_attributes.location_type               = location_type
      site_attributes.institution_url             = institution_url
      site_attributes.institution_type            = institution_type
      site_attributes.institution_email           = institution_email
      site_attributes.institution_address         = institution_address
      site_attributes.institution_document_number = institution_document_number
    end

    if @site.valid?
      @site.save
    else
      promote_errors(@site.errors)

      false
    end
  end

  protected

  def promote_errors(errors)
    errors.each do |attribute, message|
      errors.add(attribute, message)
    end
  end
end<commit_msg>Fix variable name overlapping on SiteForm errors propagation<commit_after>class SiteForm
  include ActiveModel::Model

  attr_accessor(
    :id,
    :external_id,
    :name,
    :domain,
    :configuration_data,
    :location_name,
    :location_type,
    :institution_url,
    :institution_type,
    :institution_email,
    :institution_address,
    :institution_document_number,
    :head_markup,
    :foot_markup,
    :created_at,
    :updated_at
  )

  validates :name, presence: true
  validates :location_name, presence: true
  validates :domain, presence: true, domain: true

  delegate :persisted?, to: :site

  def save
    save_site if valid?
  end

  def site
    @site ||= Site.find_by(id: id).presence || build_site
  end

  private

  def build_site
    Site.new
  end

  def save_site
    @site = site.tap do |site_attributes|
      site_attributes.name                        = name
      site_attributes.domain                      = domain
      site_attributes.configuration_data          = configuration_data
      site_attributes.location_name               = location_name
      site_attributes.location_type               = location_type
      site_attributes.institution_url             = institution_url
      site_attributes.institution_type            = institution_type
      site_attributes.institution_email           = institution_email
      site_attributes.institution_address         = institution_address
      site_attributes.institution_document_number = institution_document_number
    end

    if @site.valid?
      @site.save
    else
      promote_errors(@site.errors)

      false
    end
  end

  protected

  def promote_errors(errors_hash)
    errors_hash.each do |attribute, message|
      errors.add(attribute, message)
    end
  end
end
{'fraction_non_alphanumeric': 0.06322984904585588, 'fraction_numerical': 0.0, 'mean_word_length': 2.512, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4973348', 'n_tokens_mistral': 1025, 'n_tokens_neox': 994, 'n_words': 214}