Skip to content
smith11235 edited this page Oct 22, 2013 · 2 revisions

Default Logger

Deep Import by default uses the same logger as Rails. But to a separate file.

ActiveSupport::TaggedLogging.new(Logger.new( "log/deep_import_#{Rails.env}.log" ))

This is entirely overridable by setting your own logger. For instance the Rails default logger.

DeepImport.logger = Rails.logger # anywhere before first DeepImport.import invocation

lib/deep_import/config.rb

The handler for config/deep_import.yml

This is what tells deep import what models and associations to track

lib/deep_import/railtie.rb

Adds deep import rake tasks the the standard Rails rake tasks.

Tasks:

lib/deep_import/tasks.rake defines setup, teardown, and general info tasks

Setup

lib/deep_import/setup.rb

  • runs Teardown as a prerequisite task
  • adds DeepImportModelName for each ModelName in config file
  • adds a single migration for:
    • creating each deep_import_model_names table
    • adding deep_import_id to each models_names table

Teardown

lib/deep_import/teardown.rb

  • reverts the single migration Setup creates
  • deletes DeepImport model files

lib/deep_import/initialize.rb

  • run 1x only when DeepImport.import( options ) { block } first called
  • loads deep import logic at runtime to target model classes from config file
lib/deep_import/import_options.rb
  • allows tweaking of how tracking and association logic is setup
  • validates each option passed
  • provides a default for each option
  • can only take one configuration per process
    • cant call DeepImport.import( options ) with mutliple sets of options

lib/deep_import/model_logic.rb

  • responsible for the actual deep import logic added to target classes
    • when added, logic is by default disabled
    • when run through DeepImport.import, logic is enabled
  • sets an after_initialization callback
  • uses alias_method_chain to override belongs_to association methods

lib/deep_import/import.rb

  • Initializes the deep import environment modifications
  • Resets the models cache for tracking new instances
  • Enables deep import model logic
  • Executes the user provided block for generating model instances
  • Disables deep import model logic
  • Commit instances in the cache to the database

models_cache.rb

Tracks models in a big cache.

lib/deep_import/commit.rb

  • loads each set of models from the models cache
  • sets each belongs_to association using the deep import models
  • deletes deep_import_models

Clone this wiki locally