Class: BranchDb::Preparer

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/branch_db/preparer.rb

Overview

Checks if database needs initialization and triggers cloning if needed. Used by the db:prepare rake task enhancement.

Constant Summary

Constants included from Logging

Logging::PREFIX

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db_config, output: $stdout) ⇒ Preparer

Returns a new instance of Preparer.



9
10
11
12
# File 'lib/branch_db/preparer.rb', line 9

def initialize(db_config, output: $stdout)
  @db_config = db_config
  @output = output
end

Instance Attribute Details

#db_configObject (readonly)

Returns the value of attribute db_config.



7
8
9
# File 'lib/branch_db/preparer.rb', line 7

def db_config
  @db_config
end

#outputObject (readonly)

Returns the value of attribute output.



7
8
9
# File 'lib/branch_db/preparer.rb', line 7

def output
  @output
end

Instance Method Details

#prepare_if_neededObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/branch_db/preparer.rb', line 14

def prepare_if_needed
  log "📦 Checking database#{db_label}..."

  unless needs_cloning?
    log "✅ Database '#{config[:database]}' ready."
    return
  end

  attempt_clone
end