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

#config ⇒ Object (readonly)

Returns the value of attribute config.



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

def config
  @config
end

Instance Method Details

#current_environment_name ⇒ Object



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

#name ⇒ Object



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

def name
  config["database"]
end

#to_mysql_options ⇒ Object



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