Class: DataImport::Definition::Simple
- Inherits:
-
DataImport::Definition
- Object
- DataImport::Definition
- DataImport::Definition::Simple
- Defined in:
- lib/data-import/definition/simple.rb
Instance Attribute Summary collapse
-
#after_blocks ⇒ Object
Returns the value of attribute after_blocks.
-
#after_row_blocks ⇒ Object
Returns the value of attribute after_row_blocks.
-
#id_mappings ⇒ Object
readonly
Returns the value of attribute id_mappings.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#source_columns ⇒ Object
Returns the value of attribute source_columns.
-
#source_distinct_columns ⇒ Object
Returns the value of attribute source_distinct_columns.
-
#source_order_columns ⇒ Object
Returns the value of attribute source_order_columns.
-
#source_primary_key ⇒ Object
Returns the value of attribute source_primary_key.
-
#source_table_name ⇒ Object
Returns the value of attribute source_table_name.
-
#target_table_name ⇒ Object
Returns the value of attribute target_table_name.
Attributes inherited from DataImport::Definition
#dependencies, #name, #source_database, #target_database
Instance Method Summary collapse
- #add_id_mapping(mapping) ⇒ Object
- #definition(name = nil) ⇒ Object
-
#initialize(name, source_database, target_database) ⇒ Simple
constructor
A new instance of Simple.
- #mappings ⇒ Object
- #new_id_of(value) ⇒ Object
- #run(context) ⇒ Object
- #use_mode(mode) ⇒ Object
Methods inherited from DataImport::Definition
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_blocks ⇒ Object
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_blocks ⇒ Object
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_mappings ⇒ Object (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 |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
9 10 11 |
# File 'lib/data-import/definition/simple.rb', line 9 def mode @mode end |
#source_columns ⇒ Object
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_columns ⇒ Object
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_columns ⇒ Object
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_key ⇒ Object
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_name ⇒ Object
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_name ⇒ Object
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 |
#mappings ⇒ Object
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) = {:columns => source_columns, :distinct => source_distinct_columns} Progress.start("Importing #{name}", source_database.count(source_table_name, )) 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 |