Class: Bootstrap::Db::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/bootstrap/db/config.rb

Constant Summary collapse

DB_CONFIG_PATH =
'config/database.yml'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ Config

Returns a new instance of Config.



8
9
10
11
12
13
14
15
# File 'lib/bootstrap/db/config.rb', line 8

def initialize(settings)
  self.settings = settings
  self.adapter  = settings[Rails.env]["adapter"].to_sym

  self.dump_path = ENV['FILE'] || File.join(default_dump_path, ENV['FILE_NAME'] || default_dump_name)
  self.dump_name = File.basename(self.dump_path)
  self.dump_dir  = File.dirname(self.dump_path)
end

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



6
7
8
# File 'lib/bootstrap/db/config.rb', line 6

def adapter
  @adapter
end

#dump_dirObject

Returns the value of attribute dump_dir.



6
7
8
# File 'lib/bootstrap/db/config.rb', line 6

def dump_dir
  @dump_dir
end

#dump_nameObject

Returns the value of attribute dump_name.



6
7
8
# File 'lib/bootstrap/db/config.rb', line 6

def dump_name
  @dump_name
end

#dump_pathObject

Returns the value of attribute dump_path.



6
7
8
# File 'lib/bootstrap/db/config.rb', line 6

def dump_path
  @dump_path
end

#settingsObject

Returns the value of attribute settings.



6
7
8
# File 'lib/bootstrap/db/config.rb', line 6

def settings
  @settings
end

Class Method Details

.load!(configuration_path = File.join(Rails.root, DB_CONFIG_PATH)) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/bootstrap/db/config.rb', line 17

def self.load!(configuration_path = File.join(Rails.root, DB_CONFIG_PATH))
  unless File.exists?(configuration_path)
    raise "Error - Please ensure your '#{File.basename(configuration_path)}' exists"
  end

  config = YAML::load(ERB.new(IO.read(configuration_path)).result)

  unless config[Rails.env]["host"]
    raise "Please ensure your '#{File.basename(configuration_path)}' file has a host for the database. eg. host = localhost"
  end

  new(config)
end