Class: DataImport::Definition::Simple

Inherits:
DataImport::Definition show all
Defined in:
lib/data-import/definition/simple.rb

Instance Attribute Summary collapse

Attributes inherited from DataImport::Definition

#dependencies, #name, #source_database, #target_database

Instance Method Summary collapse

Methods inherited from DataImport::Definition

#add_dependency

Constructor Details

#initialize(name, source_database, target_database) ⇒ Simple

Returns a new instance of Simple.



11
12
13
14
15
16
17
18
19
# File 'lib/data-import/definition/simple.rb', line 11

def initialize(name, source_database, target_database)
  super
  @mode = :insert
  @id_mappings = {}
  @after_blocks = []
  @after_row_blocks = []
  @source_columns = []
  @source_order_columns = []
end

Instance Attribute Details

#after_blocksObject

Returns the value of attribute after_blocks.



8
9
10
# File 'lib/data-import/definition/simple.rb', line 8

def after_blocks
  @after_blocks
end

#after_row_blocksObject

Returns the value of attribute after_row_blocks.



8
9
10
# File 'lib/data-import/definition/simple.rb', line 8

def after_row_blocks
  @after_row_blocks
end

#id_mappingsObject (readonly)

Returns the value of attribute id_mappings.



4
5
6
# File 'lib/data-import/definition/simple.rb', line 4

def id_mappings
  @id_mappings
end

#modeObject (readonly)

Returns the value of attribute mode.



9
10
11
# File 'lib/data-import/definition/simple.rb', line 9

def mode
  @mode
end

#source_columnsObject

Returns the value of attribute source_columns.



6
7
8
# File 'lib/data-import/definition/simple.rb', line 6

def source_columns
  @source_columns
end

#source_distinct_columnsObject

Returns the value of attribute source_distinct_columns.



6
7
8
# File 'lib/data-import/definition/simple.rb', line 6

def source_distinct_columns
  @source_distinct_columns
end

#source_order_columnsObject

Returns the value of attribute source_order_columns.



6
7
8
# File 'lib/data-import/definition/simple.rb', line 6

def source_order_columns
  @source_order_columns
end

#source_primary_keyObject

Returns the value of attribute source_primary_key.



5
6
7
# File 'lib/data-import/definition/simple.rb', line 5

def source_primary_key
  @source_primary_key
end

#source_table_nameObject

Returns the value of attribute source_table_name.



6
7
8
# File 'lib/data-import/definition/simple.rb', line 6

def source_table_name
  @source_table_name
end

#target_table_nameObject

Returns the value of attribute target_table_name.



7
8
9
# File 'lib/data-import/definition/simple.rb', line 7

def target_table_name
  @target_table_name
end

Instance Method Details

#add_id_mapping(mapping) ⇒ Object



29
30
31
# File 'lib/data-import/definition/simple.rb', line 29

def add_id_mapping(mapping)
  @id_mappings.merge! mapping
end

#definition(name = nil) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/data-import/definition/simple.rb', line 37

def definition(name = nil)
  if name.nil?
    self
  else
    DataImport.definitions[name] or raise ArgumentError
  end
end

#mappingsObject



21
22
23
# File 'lib/data-import/definition/simple.rb', line 21

def mappings
  @mappings ||= {}
end

#new_id_of(value) ⇒ Object



33
34
35
# File 'lib/data-import/definition/simple.rb', line 33

def new_id_of(value)
  @id_mappings[value]
end

#run(context) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/data-import/definition/simple.rb', line 49

def run(context)
  options = {:columns => source_columns, :distinct => source_distinct_columns}
  Progress.start("Importing #{name}", source_database.count(source_table_name, options)) do
    Importer.new(context, self).run do
      Progress.step
    end
  end
end

#use_mode(mode) ⇒ Object



45
46
47
# File 'lib/data-import/definition/simple.rb', line 45

def use_mode(mode)
  @mode = mode
end