Class: Dumper::Database::Base

Inherits:
Object
  • Object
show all
Includes:
Utility::ObjectFinder
Defined in:
lib/dumper/database/base.rb

Direct Known Subclasses

MongoDB, MySQL, Redis

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utility::ObjectFinder

#find_instance_in_object_space

Constructor Details

#initialize(stack = nil) ⇒ Base

Returns a new instance of Base.



8
9
10
# File 'lib/dumper/database/base.rb', line 8

def initialize(stack = nil)
  @stack = stack
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



6
7
8
# File 'lib/dumper/database/base.rb', line 6

def filename
  @filename
end

#tmpdirObject

Returns the value of attribute tmpdir.



6
7
8
# File 'lib/dumper/database/base.rb', line 6

def tmpdir
  @tmpdir
end

Instance Method Details

#dump_pathObject



16
17
18
# File 'lib/dumper/database/base.rb', line 16

def dump_path
  "#{tmpdir}/#{filename}"
end

#dump_tool_pathObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dumper/database/base.rb', line 20

def dump_tool_path
  tool = self.class::DUMP_TOOL
  path = `which #{tool}`.chomp
  if path.empty?
    # /usr/local/mysql/bin = OSX binary, /usr/local/bin = homebrew, /usr/bin = linux
    dir = [ '/usr/local/mysql/bin', '/usr/local/bin', '/usr/bin' ].find do |i|
      File.exist?("#{i}/#{tool}")
    end
    path = "#{dir}/#{tool}" if dir
  end
  path
end

#file_extObject



12
13
14
# File 'lib/dumper/database/base.rb', line 12

def file_ext
  self.class::FILE_EXT
end

#finalizeObject



33
34
35
# File 'lib/dumper/database/base.rb', line 33

def finalize
  FileUtils.remove_entry_secure tmpdir if File.exist? tmpdir
end