Class: Dabcup::Operation::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/dabcup/operation/base.rb

Direct Known Subclasses

Clean, Clear, Dump, Get, List, Populate, Remove, Restore

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(database) ⇒ Base

Returns a new instance of Base.



8
9
10
# File 'lib/dabcup/operation/base.rb', line 8

def initialize(database)
  @database = database
end

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



4
5
6
# File 'lib/dabcup/operation/base.rb', line 4

def database
  @database
end

Instance Method Details

#best_dumps_pathObject

Try to returns the best directory path to dump the database.



22
23
24
25
26
27
28
29
# File 'lib/dabcup/operation/base.rb', line 22

def best_dumps_path
  if database.via_ssh?
    return main_storage.path if same_ssh_as_database?(main_storage)
  else
    return main_storage.path if main_storage.local?
  end
  Dir.tmpdir
end

#best_local_dumps_pathObject

Try to returns the best local directory path.



32
33
34
35
# File 'lib/dabcup/operation/base.rb', line 32

def best_local_dumps_path
  return spare_storage.path if spare_storage.local?
  Dir.tmpdir
end

#checkObject



46
47
48
49
50
51
# File 'lib/dabcup/operation/base.rb', line 46

def check
  return if not database.via_ssh?
  if not same_ssh_as_database?(main_storage)
    raise Error.new("When dumping via SSH the main storage must be local to the database.")
  end
end

#remove_local_dump?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/dabcup/operation/base.rb', line 37

def remove_local_dump?
  !main_storage.local? && (spare_storage && !spare_storage.local?)
end

#runObject

Raises:

  • (NotImplementedError)


12
13
14
# File 'lib/dabcup/operation/base.rb', line 12

def run
  raise NotImplementedError.new("Sorry")
end

#same_ssh_as_database?(storage) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
# File 'lib/dabcup/operation/base.rb', line 41

def same_ssh_as_database?(storage)
  return false if not storage.driver.is_a?(Dabcup::Storage::Driver::SFTP)
  storage.driver.host == database.tunnel.host
end

#terminateObject



16
17
18
19
# File 'lib/dabcup/operation/base.rb', line 16

def terminate
  main_storage.disconnect if main_storage
  spare_storage.disconnect if spare_storage
end