Module: Importer::Adapters::ActiveRecordAdapter

Defined in:
lib/importer/adapters/active_record_adapter.rb

Overview

Adapter for ActiveRecord models

Usage:

class Product < ActiveRecord::Base
  include Importer
end

Product.import(path_to_xml_or_csv_file)

It sends the given file to a parser and then imports detected objects. Instead of simply inserting all detected objects to database, the importer tries to determine wheter a detected object already exists. If so, the object is only updated, otherwise a new object is created.

To change the way how importer checks for existing objects (or to turn off this behavior completely) override find_on_import method. The default behavior now is to try to find existing object by detected object's id.

By default the detected object's attributes hash is literally assigned to a soon-to-be-saved object. If there is a need for more sophisticated behavior, simply override merge_attributes_on_import method.

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object


28
29
30
31
# File 'lib/importer/adapters/active_record_adapter.rb', line 28

def included(base)
  base.send(:include, InstanceMethods)
  base.send(:extend,  ClassMethods)
end