Class: Lafcadio::ObjectStore::DbConnection
- Inherits:
-
ContextualService::Service
- Object
- ContextualService::Service
- Lafcadio::ObjectStore::DbConnection
show all
- Defined in:
- lib/lafcadio/objectStore.rb
Overview
Constant Summary
collapse
- @@conn_class =
DBI
- @@db_name =
nil
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of DbConnection.
682
|
# File 'lib/lafcadio/objectStore.rb', line 682
def initialize; @dbh = load_new_dbh; end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args) ⇒ Object
706
707
708
|
# File 'lib/lafcadio/objectStore.rb', line 706
def method_missing( symbol, *args )
@dbh.send( symbol, *args )
end
|
Class Method Details
.connection_class=(aClass) ⇒ Object
678
|
# File 'lib/lafcadio/objectStore.rb', line 678
def self.connection_class=( aClass ); @@conn_class = aClass; end
|
.db_name=(db_name) ⇒ Object
680
|
# File 'lib/lafcadio/objectStore.rb', line 680
def self.db_name=( db_name ); @@db_name = db_name; end
|
Instance Method Details
#disconnect ⇒ Object
684
|
# File 'lib/lafcadio/objectStore.rb', line 684
def disconnect; @dbh.disconnect; end
|
#driver_url ⇒ Object
686
687
688
689
690
691
692
693
694
695
|
# File 'lib/lafcadio/objectStore.rb', line 686
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_dbh ⇒ Object
697
698
699
700
701
702
703
704
|
# File 'lib/lafcadio/objectStore.rb', line 697
def load_new_dbh
config = LafcadioConfig.new
dbh = @@conn_class.connect(
driver_url, config['dbuser'], config['dbpassword']
)
dbh['AutoCommit'] = false
dbh
end
|