class Worktree::DbManager

Attributes

spec[R]

Public Class Methods

new(config_file, environment = 'development') click to toggle source
# File lib/worktree/db_manager.rb, line 9
def initialize(config_file, environment = 'development')
  @spec = YAML.load_file(config_file)
  @environment = environment
end

Public Instance Methods

createdb!(db_name) click to toggle source
# File lib/worktree/db_manager.rb, line 38
def createdb!(db_name)
  cmd = if db_port
          "createdb -h localhost -p #{db_port} -T #{template} #{db_name}"
        else
          "createdb -h localhost -T #{template} #{db_name}"
        end
  Worktree.run_command cmd
end
db_port() click to toggle source
# File lib/worktree/db_manager.rb, line 22
def db_port
  if multi?
    environment_spec.dig('primary', 'port')
  else
    environment_spec['port']
  end
end
dropdb!() click to toggle source
# File lib/worktree/db_manager.rb, line 47
def dropdb!
  cmd = if db_port
          "dropdb -h localhost -p #{db_port} #{template}"
        else
          "dropdb -h localhost #{template}"
        end
  Worktree.run_command cmd
end
environment_spec() click to toggle source
# File lib/worktree/db_manager.rb, line 14
def environment_spec
  @spec.fetch(@environment, {})
end
multi?() click to toggle source
# File lib/worktree/db_manager.rb, line 18
def multi?
  environment_spec.key? 'primary'
end
template() click to toggle source
# File lib/worktree/db_manager.rb, line 30
def template
  if multi?
    environment_spec.dig('primary', 'database')
  else
    environment_spec['database']
  end
end