Class: RubyPitaya::DatabaseConnector

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/core/database_connector.rb

Instance Method Summary collapse

Constructor Details

#initialize(setup, logger = nil) ⇒ DatabaseConnector

Returns a new instance of DatabaseConnector.



8
9
10
11
12
13
# File 'lib/rubypitaya/core/database_connector.rb', line 8

def initialize(setup, logger = nil)
  @database_config = DatabaseConfig.new(setup)
  @logger = ActiveSupport::Logger.new(STDOUT)
  # TODO: Use this
  # @logger = logger || ActiveSupport::Logger.new(STDOUT)
end

Instance Method Details

#connectObject



15
16
17
18
19
# File 'lib/rubypitaya/core/database_connector.rb', line 15

def connect
  ActiveRecord::Base.establish_connection(@database_config.connection_data)
  ActiveRecord::Base.logger = @logger
  ActiveSupport::LogSubscriber.colorize_logging = true
end

#disconnectObject



21
22
23
# File 'lib/rubypitaya/core/database_connector.rb', line 21

def disconnect
  ActiveRecord::Base.connection.close
end