Class: Database

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rails_root, single, force) ⇒ Database

Returns a new instance of Database.



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

def initialize(rails_root, single, force)
  @single = single
  @rails_root = rails_root
  @generator = Generator.new(@rails_root, single, force)
end

Instance Attribute Details

#generatorObject

Returns the value of attribute generator.



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

def generator
  @generator
end

#rails_rootObject

Returns the value of attribute rails_root.



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

def rails_root
  @rails_root
end

Instance Method Details

#connect(yaml) ⇒ Object



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

def connect(yaml)
  host = yaml['development']['host']
  host ||= 'localhost'
  ActiveRecord::Base.establish_connection(:adapter => "mysql2", 
                    :database => yaml['development']['database'])
  @generator.create_factories
end

#loadObject



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

def load
  file = File.join(@rails_root, 'config', 'database.yml')
  yaml = YAML.load_file(file)
  connect(yaml)
end