Class: BranchDb::Cleaner

Inherits:
Object
  • Object
show all
Includes:
Logging, PgUtils
Defined in:
lib/branch_db/cleaner.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, input: $stdin, prefix: true, name: nil) ⇒ Cleaner

Returns a new instance of Cleaner.



10
11
12
13
14
15
16
# File 'lib/branch_db/cleaner.rb', line 10

def initialize(config, output: $stdout, input: $stdin, prefix: true, name: nil)
  @config = config.is_a?(Hash) ? config : config.configuration_hash
  @output = output
  @input = input
  @prefix = prefix
  @name = name
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#inputObject (readonly)

Returns the value of attribute input.



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

def input
  @input
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#outputObject (readonly)

Returns the value of attribute output.



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

def output
  @output
end

Instance Method Details

#list_branch_databasesObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/branch_db/cleaner.rb', line 18

def list_branch_databases
  all_dbs = all_branch_databases

  if all_dbs.empty?
    log "No branch databases found#{db_label}."
    return []
  end

  log "Found #{all_dbs.size} branch database(s)#{db_label}:"
  all_dbs.each { |db| log "  - #{db}" }
  all_dbs
end

#prune(confirm: true) ⇒ Object



36
37
38
39
# File 'lib/branch_db/cleaner.rb', line 36

def prune(confirm: true)
  delete_databases(prunable_databases, empty_msg: "No stale branch databases to prune#{db_label}.",
                                       done_msg: "Prune complete#{db_label}!", confirm:)
end

#purge(confirm: true) ⇒ Object



31
32
33
34
# File 'lib/branch_db/cleaner.rb', line 31

def purge(confirm: true)
  delete_databases(deletable_databases, empty_msg: "No old branch databases to purge#{db_label}.",
                                        done_msg: "Purge complete#{db_label}!", confirm:)
end