<commit_before>module HoboFields

  Model = classy_module do

    # ignore the model in the migration until somebody sets
    # @include_in_migration via the fields declaration
    inheriting_cattr_reader :include_in_migration => false

    # attr_types holds the type class for any attribute reader (i.e. getter
    # method) that returns rich-types
    inheriting_cattr_reader :attr_types => HashWithIndifferentAccess.new
    inheriting_cattr_reader :attr_order => []

    # field_specs holds FieldSpec objects for every declared
    # field. Note that attribute readers are created (by ActiveRecord)
    # for all fields, so there is also an entry for the field in
    # attr_types. This is redundant but simplifies the implementation
    # and speeds things up a little.
    inheriting_cattr_reader :field_specs => HashWithIndifferentAccess.new

    # index_specs holds IndexSpec objects for all the declared indexes.
    inheriting_cattr_reader :index_specs => []
    inheriting_cattr_reader :ignore_indexes => []
eval %(
    def self.inherited(klass)
      fields do |f|
        f.field(inheritance_column, :string)
      end
      index(inheritance_column)
      super
    end
)
    def self.index(fields, options = {})
      # don't double-index fields
      index_specs << HoboFields::Model::IndexSpec.new(self, fields, options) unless index_specs.*.fields.include?(Array.wrap(fields).*.to_s)
    end

    # tell the migration generator to ignore the named index. Useful for existing indexes, or for indexes
    # that can't be automatically generated (for example: an prefix index in MySQL)
    def self.ignore_index(index_name)
      ignore_indexes << index_name.to_s
    end

    private

    # Declares that a virtual field that has a rich type (e.g. created
    # by attr_accessor :foo, :type => :email_address) should be subject
    # to validation (note that the rich types know how to validate themselves)
    def self.validate_virtual_field(*args)
      validates_each(*args) {|record, field, value| msg = value.validate and record.errors.add(field, msg) if value.respond_to?(:validate) }
    end<commit_msg>added comments for 1.9.2 error and fix indentation of eval string [#840] [#869]<commit_after>module HoboFields

  Model = classy_module do

    # ignore the model in the migration until somebody sets
    # @include_in_migration via the fields declaration
    inheriting_cattr_reader :include_in_migration => false

    # attr_types holds the type class for any attribute reader (i.e. getter
    # method) that returns rich-types
    inheriting_cattr_reader :attr_types => HashWithIndifferentAccess.new
    inheriting_cattr_reader :attr_order => []

    # field_specs holds FieldSpec objects for every declared
    # field. Note that attribute readers are created (by ActiveRecord)
    # for all fields, so there is also an entry for the field in
    # attr_types. This is redundant but simplifies the implementation
    # and speeds things up a little.
    inheriting_cattr_reader :field_specs => HashWithIndifferentAccess.new

    # index_specs holds IndexSpec objects for all the declared indexes.
    inheriting_cattr_reader :index_specs => []
    inheriting_cattr_reader :ignore_indexes => []

    # eval avoids the ruby 1.9.2 "super from singleton method ..." error
    eval %(
      def self.inherited(klass)
        fields do |f|
          f.field(inheritance_column, :string)
        end
        index(inheritance_column)
        super
      end
    )

    def self.index(fields, options = {})
      # don't double-index fields
      index_specs << HoboFields::Model::IndexSpec.new(self, fields, options) unless index_specs.*.fields.include?(Array.wrap(fields).*.to_s)
    end

    # tell the migration generator to ignore the named index. Useful for existing indexes, or for indexes
    # that can't be automatically generated (for example: an prefix index in MySQL)
    def self.ignore_index(index_name)
      ignore_indexes << index_name.to_s
    end

    private

    # Declares that a virtual field that has a rich type (e.g. created
    # by attr_accessor :foo, :type => :email_address) should be subject
    # to validation (note that the rich types know how to validate themselves)
    def self.validate_virtual_field(*args)
      validates_each(*args) {|record, field, value| msg = value.validate and record.errors.add(field, msg) if value.respond_to?(:validate) }
    end
{'fraction_non_alphanumeric': 0.07429218573046432, 'fraction_numerical': 0.0027180067950169874, 'mean_word_length': 3.54320987654321, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '5415043', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1234, 'n_words': 433}