Class: Lafcadio::ObjectStore::DbConnection

Inherits:
ContextualService::Service
  • Object
show all
Defined in:
lib/lafcadio/objectStore.rb

Overview

:nodoc:

Constant Summary collapse

@@conn_class =
DBI
@@db_name =
nil

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDbConnection

Returns a new instance of DbConnection.



712
713
714
715
# File 'lib/lafcadio/objectStore.rb', line 712

def initialize
	@dbh = load_new_dbh
	ObjectSpace.define_finalizer( self, proc { |id| disconnect } )
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object



739
740
741
# File 'lib/lafcadio/objectStore.rb', line 739

def method_missing( symbol, *args )
	@dbh.send( symbol, *args )
end

Class Method Details

.connection_class=(aClass) ⇒ Object



708
# File 'lib/lafcadio/objectStore.rb', line 708

def self.connection_class=( aClass ); @@conn_class = aClass; end

.db_name=(db_name) ⇒ Object



710
# File 'lib/lafcadio/objectStore.rb', line 710

def self.db_name=( db_name ); @@db_name = db_name; end

Instance Method Details

#disconnectObject



717
# File 'lib/lafcadio/objectStore.rb', line 717

def disconnect; @dbh.disconnect; end

#driver_urlObject



719
720
721
722
723
724
725
726
727
728
# File 'lib/lafcadio/objectStore.rb', line 719

def driver_url
	config = LafcadioConfig.new
	dbName = @@db_name || config['dbname']
	driver_name = config['dbtype'] || 'Mysql'
	if dbName && config['dbhost']
		"dbi:#{ driver_name }:#{ dbName }:#{ config['dbhost'] }"
	else
		"dbi:#{config['dbconn']}"
	end
end

#load_new_dbhObject



730
731
732
733
734
735
736
737
# File 'lib/lafcadio/objectStore.rb', line 730

def load_new_dbh
	config = LafcadioConfig.new
	dbh = @@conn_class.connect(
		driver_url, config['dbuser'], config['dbpassword']
	)
	dbh['AutoCommit'] = false
	dbh
end