<commit_before># coding: utf-8

module Contentr
  class Paragraph

    # Paragraph is abstract
    @abstract_class = true

    # Includes
    include Mongoid::Document

    # Fields
    field :area_name, :type => String,  :index => true
    field :position,  :type => Integer, :index => true

    # Validations
    validates_presence_of :area_name

    # Relations
    embedded_in :page

    def self.dynamic_accessor(name, postfix='')
      define_method("#{name}#{postfix}".to_sym) do |i|
        self.send("#{name}#{i}#{postfix}".to_sym)
      end
    end

    def fields_for_simple_form
      textpatt = /text|descr|content|body/
      ul = {}
      skipped = ["_id", "_type", "position"]
      if self.class.respond_to?(:uploaders)
        ul = self.class.uploaders
        skipped += self.class.uploader_options.map(&:last).map{|h| h[:mount_on]}
      end
      self.fields.map do |f|
        name = f.first
        if skipped.member?(name) then nil else
          name = name.to_sym
          options = {}
          options[:as] = :file if ul[name]
          options[:as] = :hidden if name == :area_name
          [name, options]
        end
      end.compact
    end

  end
end<commit_msg>required false by default on auto generated fields<commit_after># coding: utf-8

module Contentr
  class Paragraph

    # Paragraph is abstract
    @abstract_class = true

    # Includes
    include Mongoid::Document

    # Fields
    field :area_name, :type => String,  :index => true
    field :position,  :type => Integer, :index => true

    # Validations
    validates_presence_of :area_name

    # Relations
    embedded_in :page

    def self.dynamic_accessor(name, postfix='')
      define_method("#{name}#{postfix}".to_sym) do |i|
        self.send("#{name}#{i}#{postfix}".to_sym)
      end
    end

    def fields_for_simple_form
      textpatt = /text|descr|content|body/
      ul = {}
      skipped = ["_id", "_type", "position"]
      if self.class.respond_to?(:uploaders)
        ul = self.class.uploaders
        skipped += self.class.uploader_options.map(&:last).map{|h| h[:mount_on]}
      end
      self.fields.map do |f|
        name = f.first
        if skipped.member?(name) then nil else
          name = name.to_sym
          options = {}
          options[:required] = false
          options[:as] = :file if ul[name]
          options[:as] = :hidden if name == :area_name
          [name, options]
        end
      end.compact
    end

  end
end
{'fraction_non_alphanumeric': 0.12317666126418152, 'fraction_numerical': 0.0008103727714748784, 'mean_word_length': 2.341001353179973, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '2864210', 'n_tokens_mistral': 808, 'n_tokens_neox': 789, 'n_words': 186}