<commit_before>class Cms::ContactForm < ActiveRecord::Base
  include Cms::Base

  belongs_to :site
  belongs_to :contact_form, class_name: 'Cms::ContactForm'
  has_many :contact_forms, class_name: 'Cms::ContactForm'
  has_many :contacts, class_name: 'Cms::Contact'

  def contact_fields
    YAML.load(read_attribute(:contact_fields) || '') || []
  end

  def contact_fields=(fields)
    field_array = case fields
                    when String
                      fields.split(/\s+/)
                    else
                      fields
                  end
    write_attribute :contact_fields, field_array.to_yaml
  end

  def contact_field_options_for(field)
    contact_field_options[field]
  end

  def contact_field_options
    @options ||= begin
      options = {}
      form_overrides = YAML.load(read_attribute(:contact_field_options) || '') || {}
      site.contact_field_definitions.each do |field, value|
        options[field] = value.merge(form_overrides[field] || {})
      end
      options
    end
  end

  def contact_field_options=(options)
    site_options = site.contact_field_definitions
    site_options.keys.each do |field|
      options.delete(field) if site_options[field] == options[field]
    end
    write_attribute :contact_field_options, options.to_yaml
  end

  def contact_field_translations
    @translations ||= site.contact_field_translations.merge(YAML.load(read_attribute(:contact_field_translations) || '') || {})
  end

  def contact_field_translations=(translations)
    site_translations = site.contact_field_translations
    site_translations.keys.each do |field|
      translations.delete(field) if site_translations[field] == translations[field]
    end
    write_attribute :contact_field_translations, translations.to_yaml
  end

  def redirect_url
    ['', read_attribute(:redirect_url).split('/')].flatten.join('/')
  end

  def build_contact(field_values={})
    contact = self.contacts.new
    contact.contact_form = self
    contact.send(:contact_fields=, field_values)
    contact
  end

end<commit_msg>clean redirect_url<commit_after>class Cms::ContactForm < ActiveRecord::Base
  include Cms::Base

  belongs_to :site
  belongs_to :contact_form, class_name: 'Cms::ContactForm'
  has_many :contact_forms, class_name: 'Cms::ContactForm'
  has_many :contacts, class_name: 'Cms::Contact'

  def contact_fields
    YAML.load(read_attribute(:contact_fields) || '') || []
  end

  def contact_fields=(fields)
    field_array = case fields
                    when String
                      fields.split(/\s+/)
                    else
                      fields
                  end
    write_attribute :contact_fields, field_array.to_yaml
  end

  def contact_field_options_for(field)
    contact_field_options[field]
  end

  def contact_field_options
    @options ||= begin
      options = {}
      form_overrides = YAML.load(read_attribute(:contact_field_options) || '') || {}
      site.contact_field_definitions.each do |field, value|
        options[field] = value.merge(form_overrides[field] || {})
      end
      options
    end
  end

  def contact_field_options=(options)
    site_options = site.contact_field_definitions
    site_options.keys.each do |field|
      options.delete(field) if site_options[field] == options[field]
    end
    write_attribute :contact_field_options, options.to_yaml
  end

  def contact_field_translations
    @translations ||= site.contact_field_translations.merge(YAML.load(read_attribute(:contact_field_translations) || '') || {})
  end

  def contact_field_translations=(translations)
    site_translations = site.contact_field_translations
    site_translations.keys.each do |field|
      translations.delete(field) if site_translations[field] == translations[field]
    end
    write_attribute :contact_field_translations, translations.to_yaml
  end

  def redirect_url
    ['', read_attribute(:redirect_url).split('/')].flatten.join('/').gsub(/\/+/,'/')
  end

  def build_contact(field_values={})
    contact = self.contacts.new
    contact.contact_form = self
    contact.send(:contact_fields=, field_values)
    contact
  end

end
{'fraction_non_alphanumeric': 0.10147378593863252, 'fraction_numerical': 0.0, 'mean_word_length': 3.461206896551724, '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': '7223582', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1242, 'n_words': 222}