Class: Dbmanager::Importer

Inherits:
Runner
  • Object
show all
Defined in:
lib/dbmanager/importer.rb

Instance Attribute Summary collapse

Attributes inherited from Runner

#environments, #input, #output

Instance Method Summary collapse

Methods inherited from Runner

#get_env, #get_filename, #initialize

Constructor Details

This class inherits a constructor from Dbmanager::Runner

Instance Attribute Details

#sourceObject

Returns the value of attribute source.



4
5
6
# File 'lib/dbmanager/importer.rb', line 4

def source
  @source
end

#targetObject

Returns the value of attribute target.



4
5
6
# File 'lib/dbmanager/importer.rb', line 4

def target
  @target
end

Instance Method Details

#adapterObject

Raises:



22
23
24
25
# File 'lib/dbmanager/importer.rb', line 22

def adapter
  raise MixedAdapterError if source.adapter != target.adapter
  Dbmanager::Adapters.const_get source.adapter.capitalize
end

#execute_importObject



18
19
20
# File 'lib/dbmanager/importer.rb', line 18

def execute_import
  adapter::Importer.new(source, target, tmp_file).run
end

#get_dataObject



13
14
15
16
# File 'lib/dbmanager/importer.rb', line 13

def get_data
  self.source = get_env('source')
  self.target = get_env('target')
end

#runObject



6
7
8
9
10
11
# File 'lib/dbmanager/importer.rb', line 6

def run
  get_data
  raise EnvironmentProtectedError if target.protected?
  execute_import
  output.puts 'Database Import completed.'
end

#tmp_fileObject



27
28
29
# File 'lib/dbmanager/importer.rb', line 27

def tmp_file
  @tmp_file ||= File.join Dbmanager.rails_root, 'tmp', Time.now.strftime('%y%m%d%H%M%S')
end