<commit_before>class Address < ActiveRecord::Base
  translates :building_name, :street_name, 
    :street_name, :province_name, :district_name, :sub_district_name,
    :extra_info

  belongs_to :addressable, polymorphic: true

  belongs_to :postal_code

  validate :dynamic_validation

  def fetch_data_from_postal_code
    if postal_code
      Setting.available_locales.each do |lang|
        Globalize.with_locale(lang) do
          self.assign_attributes(postal_code.locality)
        end
      end
      nil
    end
  end

  def dynamic_validation
    if Setting.try("#{addressable_type}_address").present?
      Setting.try("#{addressable_type}_address").each do |key, value|
        errors.add(key, t('errors.messages.blank')) if value && try(key).blank?
      end
    end
  end
end<commit_msg>Fix validate error<commit_after>class Address < ActiveRecord::Base
  translates :building_name, :street_name, 
    :street_name, :province_name, :district_name, :sub_district_name,
    :extra_info

  belongs_to :addressable, polymorphic: true

  belongs_to :postal_code

  validate :dynamic_validation

  def fetch_data_from_postal_code
    if postal_code
      Setting.available_locales.each do |lang|
        Globalize.with_locale(lang) do
          self.assign_attributes(postal_code.locality)
        end
      end
      nil
    end
  end

  def dynamic_validation
    if Setting["#{addressable_type.tableize}_address"].present?
      Setting["#{addressable_type.tableize}_address"].each do |key, value|
        errors.add(key, I18n.t('errors.messages.blank')) if value && try(key).blank?
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09074074074074075, 'fraction_numerical': 0.0012345679012345679, 'mean_word_length': 3.57909604519774, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2303670', 'n_tokens_mistral': 528, 'n_tokens_neox': 504, 'n_words': 103}