Class: DataImport::Dsl::Import

Inherits:
Object
  • Object
show all
Defined in:
lib/data-import/dsl/import.rb,
lib/data-import/dsl/import/from.rb

Defined Under Namespace

Classes: From

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition) ⇒ Import

Returns a new instance of Import.



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

def initialize(definition)
  @definition = definition
end

Instance Attribute Details

#definitionObject (readonly)

Returns the value of attribute definition.



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

def definition
  @definition
end

Instance Method Details

#after(&block) ⇒ Object



32
33
34
# File 'lib/data-import/dsl/import.rb', line 32

def after(&block)
  definition.after_blocks << block
end

#after_row(&block) ⇒ Object



36
37
38
# File 'lib/data-import/dsl/import.rb', line 36

def after_row(&block)
  definition.after_row_blocks << block
end

#dependencies(*dependencies) ⇒ Object



40
41
42
43
44
# File 'lib/data-import/dsl/import.rb', line 40

def dependencies(*dependencies)
  dependencies.each do |dependency|
    definition.add_dependency(dependency)
  end
end

#from(name = nil, options = {}, &block) ⇒ Object



10
11
12
13
14
15
# File 'lib/data-import/dsl/import.rb', line 10

def from(name = nil, options = {}, &block)
  definition.source_table_name = name
  definition.source_primary_key = options[:primary_key]

  From.new(definition).instance_eval &block if block_given?
end

#mapping(*hash_or_symbols, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/data-import/dsl/import.rb', line 22

def mapping(*hash_or_symbols, &block)
  if hash_or_symbols.first.is_a? Hash
    definition.mappings.merge! hash_or_symbols.first
  else
    symbols = hash_or_symbols
    symbols = symbols.first if symbols.count == 1
    definition.mappings[symbols] = block
  end
end

#to(name, options = {}) ⇒ Object



17
18
19
20
# File 'lib/data-import/dsl/import.rb', line 17

def to(name, options = {})
  definition.target_table_name = name
  definition.use_mode(:update) if options[:mode] == :update
end