<commit_before>class SuppliersPlugin::Consumer < SuppliersPlugin::Supplier

  self.table_name = :suppliers_plugin_suppliers

  before_save :sync_profile

  attr_accessible :email, :phone, :cell_phone, :hub_id, :address, :city, :state, :zip

  belongs_to :profile, foreign_key: :consumer_id
  belongs_to :supplier, foreign_key: :profile_id
  alias_method :consumer, :profile

  belongs_to :hub

  def name= value
    self['name'] = value
  end
  def name
    self['name']
  end
  def description= value
    self['description'] = value
  end
  def description
    self['description']
  end

  def hub_name
    self.hub.nil? ? '' : self.hub.name
  end

  def sync_profile profile=nil
    profile = self.profile if profile.nil?
    return if profile.community?

    fields = {name: :name, contact_email: :email, contact_phone: :phone, cell_phone: :cell_phone, address: :address, city: :city, state: :state, zip_code: :zip}
    dirty = false

    fields.each do |profile_k, consumer_k|
      profile_v  = profile.send "#{profile_k}"
      consumer_v = self.send "#{consumer_k}"
      if profile_v.present? && consumer_v.blank?
        self.send "#{consumer_k}=", profile_v
        dirty = true
      end
    end

    self.save if dirty
  end
end<commit_msg>Avoid errors on validations before syncing profile data<commit_after>class SuppliersPlugin::Consumer < SuppliersPlugin::Supplier

  self.table_name = :suppliers_plugin_suppliers

  before_validation :sync_profile

  attr_accessible :email, :phone, :cell_phone, :hub_id, :address, :city, :state, :zip

  belongs_to :profile, foreign_key: :consumer_id
  belongs_to :supplier, foreign_key: :profile_id
  alias_method :consumer, :profile

  belongs_to :hub

  def name= value
    self['name'] = value
  end
  def name
    self['name']
  end
  def description= value
    self['description'] = value
  end
  def description
    self['description']
  end

  def hub_name
    self.hub.nil? ? '' : self.hub.name
  end

  def sync_profile profile=nil
    profile = self.profile if profile.nil?
    return if profile.community?

    fields = {name: :name, contact_email: :email, contact_phone: :phone, cell_phone: :cell_phone, address: :address, city: :city, state: :state, zip_code: :zip}
    dirty = false

    fields.each do |profile_k, consumer_k|
      profile_v  = profile.send "#{profile_k}"
      consumer_v = self.send "#{consumer_k}"
      if profile_v.present? && consumer_v.blank?
        self.send "#{consumer_k}=", profile_v
        dirty = true
      end
    end

  end
end
{'fraction_non_alphanumeric': 0.10715697904310004, 'fraction_numerical': 0.0, 'mean_word_length': 3.616788321167883, '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': '4436668', 'n_tokens_mistral': 842, 'n_tokens_neox': 815, 'n_words': 219}