Class: Dabcup::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/dabcup/database.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, config) ⇒ Database

Returns a new instance of Database.



11
12
13
14
15
16
17
# File 'lib/dabcup/database.rb', line 11

def initialize(name, config)
  @name = name
  @config = config
  @main_storage = Dabcup::Storage.new(config['storage'])
  @spare_storage = Dabcup::Storage.new(config['spare_storage']) if config['spare_storage']
  extend(Tunnel) if tunnel
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/dabcup/database.rb', line 7

def config
  @config
end

#main_storageObject (readonly)

Returns the value of attribute main_storage.



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

def main_storage
  @main_storage
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#spare_storageObject (readonly)

Returns the value of attribute spare_storage.



9
10
11
# File 'lib/dabcup/database.rb', line 9

def spare_storage
  @spare_storage
end

Instance Method Details

#dump(dump_path) ⇒ Object



27
28
29
# File 'lib/dabcup/database.rb', line 27

def dump(dump_path)
  system(config['dump'], :dump_path => File.expand_path(dump_path))
end

#retentionObject



39
40
41
# File 'lib/dabcup/database.rb', line 39

def retention
  config['retention']
end

#system(command, interpolation = {}) ⇒ Object

Raises:



31
32
33
34
35
36
37
# File 'lib/dabcup/database.rb', line 31

def system(command, interpolation = {})
  command = command % interpolation
  # TODO Found a nice way to get the exit status.
  stdin, stdout, stderr = Open3.popen3(command + "; echo $?")
  raise Dabcup::Error.new("Failed to execute '#{command}', stderr is '#{stderr.read}'.") if not stderr.eof?
  [stdin, stdout, stderr]
end

#tunnelObject



19
20
21
# File 'lib/dabcup/database.rb', line 19

def tunnel
  @tunnel ||= Addressable::URI.parse(config['tunnel']) if config['tunnel']
end

#via_ssh?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/dabcup/database.rb', line 23

def via_ssh?
  tunnel != nil
end