Class: BranchDb::Cloner

Inherits:
Object
  • Object
show all
Includes:
Logging, PgUtils
Defined in:
lib/branch_db/cloner.rb

Constant Summary

Constants included from Logging

Logging::PREFIX

Constants included from PgUtils

PgUtils::PG_TOOLS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, output: $stdout) ⇒ Cloner

Returns a new instance of Cloner.



8
9
10
11
# File 'lib/branch_db/cloner.rb', line 8

def initialize(config, output: $stdout)
  @config = config.is_a?(Hash) ? config : config.configuration_hash
  @output = output
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/branch_db/cloner.rb', line 6

def config
  @config
end

#outputObject (readonly)

Returns the value of attribute output.



6
7
8
# File 'lib/branch_db/cloner.rb', line 6

def output
  @output
end

Instance Method Details

#cloneObject



13
14
15
16
17
# File 'lib/branch_db/cloner.rb', line 13

def clone
  log "📦 Cloning #{source_db} → #{target_db}..."
  create_or_recreate_database
  transfer_data
end

#source_dbObject



24
# File 'lib/branch_db/cloner.rb', line 24

def source_db = @source_db ||= determine_source_db

#source_exists?Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/branch_db/cloner.rb', line 19

def source_exists?
  check_pg_tools!(:psql, :pg_dump)
  database_exists?(source_db)
end

#target_dbObject



26
# File 'lib/branch_db/cloner.rb', line 26

def target_db = config[:database]