Class: Backhoe::Database

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = load_config) ⇒ Database

Returns a new instance of Database.



3
4
5
# File 'lib/backhoe/database.rb', line 3

def initialize config=load_config
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

Instance Method Details

#adapterObject



29
30
31
# File 'lib/backhoe/database.rb', line 29

def adapter
  config["adapter"]
end

#current_environment_nameObject



9
10
11
12
13
14
15
# File 'lib/backhoe/database.rb', line 9

def current_environment_name
  [
    defined?(Rails) && Rails.env,
    ENV["RAILS_ENV"],
    "development",
  ].find(&:itself)
end

#mysql?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/backhoe/database.rb', line 37

def mysql?
  %w[mysql2 trilogy].include?(config["adapter"])
end

#nameObject



25
26
27
# File 'lib/backhoe/database.rb', line 25

def name
  config["database"]
end

#postgresql?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/backhoe/database.rb', line 33

def postgresql?
  config["adapter"] == "postgresql"
end

#to_mysql_optionsObject



17
18
19
20
21
22
23
# File 'lib/backhoe/database.rb', line 17

def to_mysql_options
  options =  " -u #{config["username"]}"
  options += " -p'#{config["password"]}'" if config["password"]
  options += " -h #{config["host"]}"      if config["host"]
  options += " -S #{config["socket"]}"    if config["socket"]
  options
end