Auditing creates audit objects for a record.

 @examples
   class School < ActiveRecord::Base
      audit_enabled
   end
   class School < ActiveRecord::Base
     audit_enabled :fields => [:name, :established_on]
   end
421473
def audit_enabled(opts={})
      include InstanceMethods

      class_attribute :auditing_fields

      has_many :audits, :as => :auditable, :order => 'created_at DESC, id DESC'

      self.auditing_fields = gather_fields_for_auditing(opts[:fields])

      after_create :log_creation
      after_update :log_update
    end
914118
def reflected_names(obj)
      classes = obj.reflections
      class_names = []
      classes.each do |key, cl|
        if eval(cl.class_name).respond_to?("diffable") \
           and cl.association_class != ActiveRecord::Associations::BelongsToAssociation
          class_names << key
        end
      end
      class_names
    end
359606
def restore_record(record, attributes)
      primary_key = record.class.primary_key
      primary_key = [primary_key].compact unless primary_key.is_a?(Array)
      primary_key.each do |key|
        record.send("#{key.to_s}=", attributes[key.to_s])
      end

      attrs, association_attrs = attributes_and_associations(record.class, attributes)
      attrs.each_pair do |key, value|
        begin
          record.send("#{key}=", value)
        rescue
          record.errors.add(key.to_sym, "could not be restored to #{value.inspect}")
        end
      end

      association_attrs.each_pair do |key, values|
        restore_association(record, key, values) if values
      end
      
      # Check if the record already exists in the database and restore its state.
      # This must be done last because otherwise associations on an existing record
      # can be deleted when a revision is restored to memory.
      exists = record.class.find(record.send(record.class.primary_key)) rescue nil
      if exists
        record.instance_variable_set(:@new_record, nil) if record.instance_variable_defined?(:@new_record)
        # ActiveRecord 3.0.2 and 3.0.3 used @persisted instead of @new_record
        record.instance_variable_set(:@persisted, true) if record.instance_variable_defined?(:@persisted)
      end
    end
966171
def errors
      found_errors = @record.all('[data-error-for]')
      error_list = ActiveModel::Errors.new(self)
      found_errors.each do | error |
        attribute = error['data-error-for']
        message = error.text
        error_list.add(attribute, message)
      end
      error_list
    end
1079413
def nested_form_for_main_fields(klass, nested_klass, options={})
      form_for_main_fields(klass,options) do |form_field|
        nested_table_name = nested_klass.to_s.underscore.pluralize.to_sym
        main_model_name = klass.to_s.underscore.to_sym
        form_field.has_many nested_table_name, allow_destroy: true do |form|
          nested_klass.main_fields.map { |f| ExtensionedSymbol.new(f).cut_id }.each do |nested_field|
            current_options = options.fetch(nested_table_name){{}}.fetch(nested_field){{}}
            form.input(nested_field, current_options) unless nested_field == main_model_name
          end
        end
      end
    end
1188636
def _create_record(name, field_defs, step_name, inputs, unlist, file_vs, std_vs, parallel):
    
    if field_defs:
        fields = []
        inherit = []
        inherit_all = False
        inherit_exclude = []
        for fdef in field_defs:
            if not fdef.get("type"):
                if fdef["id"] == "inherit":
                    inherit_all = True
                    inherit_exclude = fdef.get("exclude", [])
                else:
                    inherit.append(fdef["id"])
            else:
                cur = {"name": _get_string_vid(fdef["id"]),
                       "type": fdef["type"]}
                fields.append(_add_secondary_to_rec_field(fdef, cur))
        if inherit_all:
            fields.extend(_infer_record_outputs(inputs, unlist, file_vs, std_vs, parallel, exclude=inherit_exclude))
        elif inherit:
            fields.extend(_infer_record_outputs(inputs, unlist, file_vs, std_vs, parallel, inherit))
    else:
        fields = _infer_record_outputs(inputs, unlist, file_vs, std_vs, parallel)
    out = {"id": "%s/%s" % (step_name, name),
           "type": {"name": name,
                    "type": "record",
                    "fields": fields}}
    if parallel in ["batch-single", "multi-batch"]:
        out = _nest_variable(out)
    return out
5885
def record_from_hash(data)
      attributes = data.delete('attributes')
      new_record = find_or_materialize(attributes["type"]).new
      data.each do |name, value|
        field = new_record.description['fields'].find do |field|
          key_from_label(field["label"]) == name || field["name"] == name || field["relationshipName"] == name
        end

        # Field not found
        if field == nil
          break
        end

        # If reference/lookup field data was fetched, recursively build the child record and apply
        if value.is_a?(Hash) and field['type'] == 'reference' and field["relationshipName"]
          relation = record_from_hash( value )
          set_value( new_record, field["relationshipName"], relation, 'reference' )

        # Apply the raw value for all other field types
        else
          set_value(new_record, field["name"], value, field["type"]) if field
        end
      end
      new_record
    end
222958
def assert_concrete_activerecord_class(class_name)
      if class_name.constantize.abstract_class?
        raise format(::PaperTrail::ModelConfig::E_HPT_ABSTRACT_CLASS, @model_class, class_name)
      end
    end
986029
def create
      return false unless new_record?
      run_callbacks :save do
        run_callbacks :create do
          httparty = self.class.post(self.class.index_path, request_options.merge(:body => to_json))
          handle_save_response(httparty)
        end
      end
    end
1128200
def activities
      query = Audited::Adapters::ActiveRecord::Audit.where(auditable_id: translation_ids).all
      query = query.where("DATE(created_at) <= DATE(?)", created_at_lteq) unless created_at_lteq.blank?
      query = query.where("DATE(created_at) >= DATE(?)", created_at_gteq) unless created_at_gteq.blank?
      query.order('created_at DESC')
    end
1051549
def class_of(object)
      case object
      when ActiveRecord::Base
        object.class
      when ActiveRecord::Relation
        object.klass
      when String
        object.constantize
      else
        object
      end
    end
586969
def create(cls, values, **context):
        
        schema = cls.schema()
        model = cls

        # check for creating inherited classes from a sub class
        polymorphic_columns = schema.columns(flags=orb.Column.Flags.Polymorphic)
        if polymorphic_columns:
            polymorphic_column = polymorphic_columns.values()[0]
            schema_name = values.get(polymorphic_column.name(), schema.name())
            if schema_name and schema_name != schema.name():
                schema = orb.system.schema(schema_name)
                if not schema:
                    raise orb.errors.ModelNotFound(schema=schema_name)
                else:
                    model = schema.model()

        column_values = {}
        collector_values = {}

        for key, value in values.items():
            obj = schema.collector(key) or schema.column(key)
            if isinstance(obj, orb.Collector):
                collector_values[key] = value
            else:
                column_values[key] = value

        # create the new record with column values (values stored on this record)
        record = model(context=orb.Context(**context))
        record.update(column_values)
        record.save()

        # save any collector values after the model is generated (values stored on other records)
        record.update(collector_values)

        return record
117743
@Override
    public void serialize(List<org.audit4j.core.dto.Field> auditFields, Object object,
            String objectName, DeIdentify deidentify) {
        visited.clear();
        String text = toString(object, deidentify);
        auditFields.add(new org.audit4j.core.dto.Field(objectName, text, object.getClass().getName()));
    }
1355069
def record_changed?(reflection, record, key)
        record.new_record? ||
          association_foreign_key_changed?(reflection, record, key) ||
          record.will_save_change_to_attribute?(reflection.foreign_key)
      end
585673
def revision
      clazz = auditable_type.constantize
      (clazz.find_by_id(auditable_id) || clazz.new).tap do |m|
        self.class.assign_revision_attributes(m, self.class.reconstruct_attributes(ancestors).merge(audit_version: version))
      end
    end
365855
def define_record_methods record
      record.class_eval <<-RUBY, __FILE__, __LINE__ + 1
        def #{name};        tuple.fetch(:#{field}, nil)   end
        def #{name}= value; tuple.store(:#{field}, value) end
      RUBY
    end
375363
def class_and_id(record_or_hash)
      if record_or_hash.is_a?(Hash)
        [record_or_hash[:class], record_or_hash[:id]]
      else
        [record_or_hash.class, Sunspot::Adapters::InstanceAdapter.adapt(record_or_hash).id]
      end
    end